电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> delphi技术>>DELPHI基础开发技巧(中):

DELPHI基础开发技巧(中)

来源:www.cncfan.com | 2006-1-17 | (有2442人读过)

◇[DELPHI]获取某一计算机上的共享目录
procedure getsharefolder(const computername:string);
var
errcode,a:integer;
netres:array[0..1023] of netresource;
enumhandle:thandle;
enumentries,buffersize:dword;
s:string;
mylistitems:tlistitems;
mylistitem:tlistitem;
mystrings:tstringlist;
begin
with netres[0] do begin
dwscope :=RESOURCE_GLOBALNET;
dwtype :=RESOURCETYPE_DISK;
dwdisplaytype :=RESOURCEDISPLAYTYPE_SHARE;
dwusage :=RESOURCEUSAGE_CONTAINER;
lplocalname :=nil;
lpremotename :=pchar(computername);
lpcomment :=nil;
lpprovider :=nil;
end; // 获取根结点
errcode:=wnetopenenum(RESOURCE_GLOBALNET,RESOURCETYPE_DISK,RESOURCEUSAGE_CONTAINER,@netres[0],enumhandle);
if errcode=NO_ERROR then
begin
EnumEntries:=1024;
BufferSize:=SizeOf(NetRes);
ErrCode:=WNetEnumResource(EnumHandle,EnumEntries,@NetRes[0],BufferSize);
end;
wnetcloseenum(enumhandle);
a:=0;
mylistitems:=controlcenter.lstfile.Items ;
mylistitems.Clear ;
while (string(netres[a].lpprovider)<>'''') and (errcode=NO_ERROR) do
begin
with mylistitems do
begin
mylistitem:=add;
mylistitem.ImageIndex :=4;
mylistitem.Caption :=extractfilename(netres[a].lpremotename);
end;
a:=a+1;
end;
end;
◇[DELPHI]得到硬盘序列号
var SerialNum : pdword; a, b : dword; Buffer : array [0..255] of char;
begin
if GetVolumeInformation(''c:\'', Buffer, SizeOf(Buffer), SerialNum, a, b, nil, 0) then Label1.Caption := IntToStr(SerialNum^);
end;
◇[DELPHI]MEMO的自动翻页
Procedure ScrollMemo(Memo : TMemo; Direction : char);
begin
case direction of
''d'': begin
SendMessage(Memo.Handle, { HWND of the Memo Control }
WM_VSCROLL, { Windows Message }
SB_PAGEDOWN, { Scroll Command }
0) { Not Used }
end;
''u'' : begin
SendMessage(Memo.Handle, { HWND of the Memo Control }
WM_VSCROLL, { Windows Message }
SB_PAGEUP, { Scroll Command }
0); { Not Used }
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ScrollMemo(Memo1,''d''); //上翻页
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ScrollMemo(Memo1,''u''); //下翻页
end;
◇[DELPHI]DBGrid中回车到下个位置(Tab键)
procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
if DBGrid1.Columns.Grid.SelectedIndex < DBGrid1.Columns.Count - 1 then
DBGrid1.Columns[DBGrid1.Columns.grid.SelectedIndex + 1].Field.FocusControl
else
begin
Table1.next;
DBGrid1.Columns[0].field.FocusControl;
end;
end;
◇[DELPHI]如何安装控件
安装方法:
1.对于单个控件,Component-->install component..-->PAS或DCU文件-->install
2.对于带*.dpk文件的控件包,File-->open(下拉列表框中选*.dpk)-->install即可.
3.对于带*.dpl文件的控件包,Install Packages-->Add-->dpl文件名即可。
4.如果以上Install按钮为失效的话,试试Compile按钮。
5.是run time lib则在option下的packages下的runtimepackes加之.
如果编译时提示文件找不到的话,一般是控件的安装目录不在delphi的Lib目录中,有两种方法可以解决:
1.把安装的原文件拷入到delphi的Lib目录下。
2.或者Tools-->Environment Options中把控件原代码路径加入到Delphi的Lib目录中即可。
◇[DELPHI]目录完全删除(deltree)
procedure TForm1.DeleteDirectory(strDir:String);
var
sr: TSearchRec;
FileAttrs: Integer;
strfilename:string;
strPth:string;
begin
strpth:=Getcurrentdir();
FileAttrs := faAnyFile;
if FindFirst(strpth+''\''+strdir+''\*.*'', FileAttrs, sr) = 0 then
begin
if (sr.Attr and FileAttrs) = sr.Attr then
begin
strfilename:=sr.Name;
if fileexists(strpth+''\''+strdir+''\''+strfilename) then
deletefile(strpth+''\''+strdir+''\''+strfilename);
end;
while FindNext(sr) = 0 do
begin
if (sr.Attr and FileAttrs) = sr.Attr then
begin
strfilename:=sr.name;
if fileexists(strpth+''\''+strdir+''\''+strfilename) then
deletefile(strpth+''\''+strdir+''\''+strfilename);
end;
end;
FindClose(sr);
removedir(strpth+''\''+strdir);
end;
end;
◇[DELPHI]取得TMemo 控件当前光标的行和列信息到Tpoint中
1.function ReadCursorPos(SourceMem TMemo): TPoint;
var Point: TPoint;
begin
 point.y := SendMessage(SourceMemo.Handle,EM_LINEFROMCHAR,SourceMemo.SelStart,0);
 point.x := SourceMemo.SelStart-SendMessage(SourceMemo.Handle,EM_LINEINDEX,point.y,0);
 Result := Point;
end;
2.LineLength:=SendMessage(memol.handle,EM-LINELENGTH,Cpos,0);//行长
◇[DELPHI]读硬盘序列号
function GetDiskSerial(DiskChar: Char): string;
var
SerialNum : pdword;
a, b : dword;
Buffer : array [0..255] of char;
begin
result := "";
if GetVolumeInformation(PChar(diskchar+":\"), Buffer, SizeOf(Buffer), SerialNum,
a, b, nil, 0) then
 Result := IntToStr(SerialNum^);
end;
◇[INTERNET]CSS常用综合技巧
1。P:first-letter { font-size: 300%; float: left }//首字会比普通字体加大三倍。
2。//连接一个外部样式表
3。嵌入一个样式表
4。 //内联样式
Arial//SPAN接受STYLE、CLASS和ID属性


DIV可以包含段落、标题、表格甚至其它部分


5。CLASS属性
//定义见3。
6。ID属性

//定义见3。
7。属性列表
字体风格:font-style: [normal | italic | oblique];
字体大小:font-size: [xx-small | x-small | small | medium | large | x-large | xx-large | larger | smaller | <长度> | <百分比>]
文本修饰:text-decoration:[ underline || overline || line-through || blink ]
文本转换:text-transform:[none | capitalize | uppercase | lowercase]
背景颜色:background-color:[<颜色> | transparent]
背景图象:background-image:[ | none]
行高:line-height: [normal | <数字> | <长度> | <百分比>]
边框样式:border-style: [ none | dotted | dashed | solid | double | groove | ridge | inset | outset ]
漂浮:float: [left | right | none]
8。长度单位
相对单位:
em (em,元素的字体的高度)
ex (x-height,字母 "x" 的高度)
px (像素,相对于屏幕的分辨率)
绝对长度:
in (英寸,1英寸=2.54厘米)
cm (厘米,1厘米=10毫米)
mm (米)
pt (点,1点=1/72英寸)
pc (帕,1帕=12点)
◇[DELPHI]VCL制作简要步骤
1.创建部件属性方法事件
(建立库单元,继承为新的类型,添加属性、方法、事件,注册部件,建立包文件)
2.消息处理
3.异常处理
4.部件可视
◇[DELPHI]动态连接库的装载
静态装载:procedure name;external ''lib.dll'';
动态装载:var handle:Thandle;
handle:=loadlibrary(''lib.dll'');
if handle<>0 then
begin
{dosomething}
freelibrary(handle);
end;
◇[DELPHI]指针变量和地址
var x,y:integer;p:^integer;//指向INTEGER变量的指针
x:=10;//变量赋值
p:=@x;//变量x的地址
y:=p^;//为Y赋值指针P
@@procedure//返回过程变量的内存地址
◇[DELPHI]判断字符是汉字的一个字符
ByteType(''你好haha吗'',1) = mbLeadByte//是第一个字符
ByteType(''你好haha吗'',2) = mbTrailByte//是第二个字符
ByteType(''你好haha吗'',5) = mbSingleByte//不是中文字符
◇[DELPHI]memo的定位操作
memo1.lines.delete(0)//删除第1行
memo1.selstart:=10//定位10字节处
◇[DELPHI]获得双字节字符内码
function getit(s: string): integer;
begin
Result := byte(s[1]) * $100 + byte(s[2]);
end;
使用:getit(''计'')//$bcc6 即十进制 48326
delphi技术热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号