Delphi编程技巧集锦
点击次数:52 次 发布日期:2008-11-09 08:41:40 作者:源代码网
|
源代码网推荐 uses shellapi; 源代码网推荐 copyfile(pchar("newfile.txt"),pchar("//computername/direction/targer.txt"),false); 源代码网推荐 源代码网推荐 ◇[DELPHI]产生鼠标拖动效果 源代码网推荐 通过MouseMove事件、DragOver事件、EndDrag事件实现,例如在PANEL上的LABEL: 源代码网推荐 var xpanel,ypanel,xlabel,ylabel:integer; 源代码网推荐 PANEL的MouseMove事件:xpanel:=x;ypanel:=y; 源代码网推荐 PANEL的DragOver事件:xpanel:=x;ypanel:=y; 源代码网推荐 LABEL的MouseMove事件:xlabel:=x;ylabel:=y; 源代码网推荐 LABEL的EndDrag事件:label.left:=xpanel-xlabel;label.top:=ypanel-ylabel; 源代码网推荐 源代码网推荐 ◇[DELPHI]取得WINDOWS目录 源代码网推荐 uses shellapi; 源代码网推荐 var windir:array[0..255] of char; 源代码网推荐 getwindowsdirectory(windir,sizeof(windir)); 源代码网推荐 或者从注册表中读取,位置: 源代码网推荐 HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersion 源代码网推荐 SystemRoot键,取得如:C:WINDOWS 源代码网推荐 源代码网推荐 ◇[DELPHI]在FORM或其他容器上画线 源代码网推荐 var x,y:array [0..50] of integer; 源代码网推荐 canvas.pen.color:=clred; 源代码网推荐 canvas.pen.style:=psDash; 源代码网推荐 form1.canvas.moveto(trunc(x[i]),trunc(y[i])); 软件开发网 www.mscto.com 源代码网推荐 form1.canvas.lineto(trunc(x[j]),trunc(y[j])); 源代码网推荐 源代码网推荐 ◇[DELPHI]字符串列表使用 源代码网推荐 var tips:tstringlist; 源代码网推荐 tips:=tstringlist.create; 源代码网推荐 tips.loadfromfile("filename.txt"); 源代码网推荐 edit1.text:=tips[0]; 源代码网推荐 tips.add("last line addition string"); 源代码网推荐 tips.insert(1,"insert string at NO 2 line"); 源代码网推荐 tips.savetofile("newfile.txt"); 源代码网推荐 tips.free; 源代码网推荐 源代码网推荐 ◇[DELPHI]简单的剪贴板操作 源代码网推荐 richedit1.selectall; 源代码网推荐 richedit1.copytoclipboard; 源代码网推荐 richedit1.cuttoclipboard; 源代码网推荐 edit1.pastefromclipboard; 源代码网推荐 源代码网推荐 ◇[DELPHI]关于文件、目录操作 源代码网推荐 Chdir("c:abcdir");转到目录 源代码网推荐 Mkdir("dirname");建立目录 源代码网推荐 Rmdir("dirname");删除目录 源代码网推荐 GetCurrentDir;//取当前目录名,无"" 源代码网推荐 Getdir(0,s);//取工作目录名s:="c:abcdir"; 源代码网推荐 Deletfile("abc.txt");//删除文件 源代码网推荐 Renamefile("old.txt","new.txt");//文件更名 源代码网推荐 ExtractFilename(filelistbox1.filename);//取文件名 源代码网推荐 ExtractFileExt(filelistbox1.filename);//取文件后缀 源代码网推荐 源代码网推荐 ◇[DELPHI]处理文件属性 源代码网推荐 attr:=filegetattr(filelistbox1.filename); 源代码网推荐 if (attr and faReadonly)=faReadonly then ... //只读 源代码网推荐 if (attr and faSysfile)=faSysfile then ... //系统 源代码网推荐 if (attr and faArchive)=faArchive then ... //存档 源代码网推荐 if (attr and faHidden)=faHidden then ... //隐藏 源代码网推荐 源代码网推荐 ◇[DELPHI]执行程序外文件 源代码网推荐 WINEXEC//调用可执行文件 源代码网推荐 winexec("command.com /c copy *.* c:",SW_Normal); 源代码网推荐 winexec("start abc.txt"); 源代码网推荐 ShellExecute或ShellExecuteEx//启动文件关联程序 源代码网推荐 function executefile(const filename,params,defaultDir:string;showCmd:integer):THandle; 源代码网推荐 ExecuteFile("C:abca.txt","x.abc","c:abc",0); 源代码网推荐 ExecuteFile("http://tingweb.yeah.net","","",0); 源代码网推荐 ExecuteFile("mailto:tingweb@wx88.net","","",0); 源代码网推荐 源代码网推荐 ◇[DELPHI]取得系统运行的进程名 源代码网推荐 var hCurrentWindow:HWnd;szText:array[0..254] of char; 源代码网推荐 begin 源代码网推荐 hCurrentWindow:=Getwindow(handle,GW_HWndFrist); 源代码网推荐 while hCurrentWindow <> 0 do 源代码网推荐 begin 源代码网推荐 if Getwindowtext(hcurrnetwindow,@sztext,255)>0 then listbox1.items.add(strpas(@sztext)); 源代码网推荐 hCurrentWindow:=Getwindow(hCurrentwindow,GW_HWndNext); 源代码网推荐 end; 源代码网推荐 end; 源代码网推荐 源代码网推荐 ◇[DELPHI]关于汇编的嵌入 源代码网推荐 Asm End; 源代码网推荐 可以任意修改EAX、ECX、EDX;不能修改ESI、EDI、ESP、EBP、EBX。 源代码网推荐 源代码网推荐 ◇[DELPHI]关于类型转换函数 源代码网推荐 FloatToStr//浮点转字符串 源代码网推荐 FloatToStrF//带格式的浮点转字符串 源代码网推荐 IntToHex//整数转16进制 源代码网推荐 TimeToStr 源代码网推荐 DateToStr 源代码网推荐 DateTimeToStr 源代码网推荐 FmtStr//按指定格式输出字符串 源代码网推荐 FormatDateTime("YYYY-MM-DD,hh-mm-ss",DATE); 源代码网推荐 源代码网推荐 ◇[DELPHI]字符串的过程和函数 源代码网推荐 Insert(obj,target,pos);//字符串target插入在pos的位置。如插入结果大于target最大长度,多出字符将被截掉。如Pos在255以外,会产生运行错。例如,st:="Brian",则Insert("OK",st,2)会使st变为"BrOKian"。 源代码网推荐 Delete(st,pos,Num);//从st串中的pos(整型)位置开始删去个数为Num(整型)个字符的子字串。例如,st:="Brian",则Delete(st,3,2)将变为Brn。 源代码网推荐 Str(value,st);//将数值value(整型或实型)转换成字符串放在st中。例如,a=2.5E4时,则str(a:10,st)将使st的值为" 25000"。 源代码网推荐 Val(st,var,code);//把字符串表达式st转换为对应整型或实型数值,存放在var中。St必须是一个表示数值的字符串,并符合数值常数的规则。在转换过程中,如果没有检测出错误,变量code置为0,否则置为第一个出错字符的位置。例如,st:=25.4E3,x是一个实型变量,则val(st,x,code)将使X值为25400,code值为0。 源代码网推荐 Copy(st.pos.num);//返回st串中一个位置pos(整型)处开始的,含有num(整型)个字符的子串。如果pos大于st字符串的长度,那就会返回一个空串,如果pos在255以外,会引起运行错误。例如,st:="Brian",则Copy(st,2,2)返回"ri"。 源代码网推荐 Concat(st1,st2,st3……,stn);//把所有自变量表示出的字符串按所给出的顺序连接起来,并返回连接后的值。如果结果的长度255,将产生运行错误。例如,st1:="Brian",st2:=" ",st3:="Wilfred",则Concat(st1,st2,st3)返回"Brian Wilfred"。 源代码网推荐 Length(st);//返回字符串表达式st的长度。例如,st:="Brian",则Length(st)返回值为5。 源代码网推荐 Pos(obj,target);//返回字符串obj在目标字符串target的第一次出现的位置,如果target没有匹配的串,Pos函数的返回值为0。例如,target:="Brian Wilfred",则Pos("Wil",target)的返回值是7,Pos("hurbet",target)的返回值是0。 源代码网推荐 源代码网推荐 ◇[DELPHI]关于处理注册表 源代码网推荐 uses Registry; 源代码网推荐 var reg:Tregistry; 源代码网推荐 reg:=Tregistry.create; 源代码网推荐 reg.rootkey:="HKey_Current_User"; 源代码网推荐 reg.openkey("Control PanelDesktop",false); 源代码网推荐 reg.WriteString("Title Wallpaper","0"); 源代码网推荐 reg.writeString("Wallpaper",filelistbox1.filename); 源代码网推荐 reg.closereg; 源代码网推荐 reg.free; 源代码网推荐 源代码网推荐 ◇[DELPHI]关于键盘常量名 源代码网推荐 VK_BACK/VK_TAB/VK_RETURN/VK_SHIFT/VK_CONTROL/VK_MENU/VK_PAUSE/VK_ESCAPE 源代码网推荐 /VK_SPACE/VK_LEFT/VK_RIGHT/VK_UP/VK_DOWN 源代码网推荐 F1--F12:$70(112)--$7B(123) 源代码网推荐 A-Z:$41(65)--$5A(90) 源代码网推荐 0-9:$30(48)--$39(57) 源代码网推荐 ◇[DELPHI]初步判断程序母语 源代码网推荐 DELPHI软件的DOS提示:This Program Must Be Run Under Win32. 源代码网推荐 VC 软件的DOS提示:This Program Cannot Be Run In DOS Mode. 源代码网推荐 源代码网推荐 ◇[DELPHI]操作Cookie 源代码网推荐 response.cookies("name").domain:="http://www.086net.com"; 源代码网推荐 with response.cookies.add do 源代码网推荐 begin 源代码网推荐 name:="username"; 源代码网推荐 value:="username"; 源代码网推荐 end 源代码网推荐 源代码网推荐 ◇[DELPHI]增加到文档菜单连接 源代码网推荐 uses shellapi,shlOBJ; 源代码网推荐 shAddToRecentDocs(shArd_path,pchar(filepath));//增加连接 源代码网推荐 shAddToRecentDocs(shArd_path,nil);//清空 源代码网推荐 源代码网推荐 ◇[杂类]备份智能ABC输入法词库 源代码网推荐 windowssystemuser.rem 源代码网推荐 windowssystem mmr.rem 源代码网推荐 源代码网推荐 ◇[DELPHI]判断鼠标按键 源代码网推荐 if GetAsyncKeyState(VK_LButton)<>0 then ... //左键 源代码网推荐 if GetAsyncKeyState(VK_MButton)<>0 then ... //中键 源代码网推荐 if GetAsyncKeyState(VK_RButton)<>0 then ... //右键 源代码网推荐 源代码网推荐 ◇[DELPHI]设置窗体的最大显示 源代码网推荐 onFormCreate事件 源代码网推荐 self.width:=screen.width; 源代码网推荐 self.height:=screen.height; 源代码网推荐 源代码网推荐 ◇[DELPHI]按键接受消息 源代码网推荐 OnCreate事件中处理:Application.OnMessage:=MyOnMessage; 源代码网推荐 procedure TForm1.MyOnMessage(var MSG:TMSG;var Handle:Boolean); 源代码网推荐 begin 源代码网推荐 if msg.message=256 then ... //ANY键 源代码网推荐 if msg.message=112 then ... //F1 源代码网推荐 if msg.message=113 then ... //F2 源代码网推荐 end; 源代码网推荐 源代码网推荐 ◇[杂类]隐藏共享文件夹 源代码网推荐 共享效果:可访问,但不可见(在资源管理、网络邻居中) 源代码网推荐 取共享名为:direction$ 源代码网推荐 访问://computer/dirction/ 源代码网推荐 源代码网推荐 ◇[Java Script]Java Script网页常用效果 源代码网推荐 网页60秒定时关闭 源代码网推荐 <script language="java script"><!-- 源代码网推荐 settimeout("window.close();",60000) 源代码网推荐 --></script> 源代码网推荐 关闭窗口 源代码网推荐 <a href="/" onclick="javascript:window.close();return false;">关闭 源代码网推荐 定时转URL 源代码网推荐 <meta http-equiv="refresh" content="40;url=http://www.086net.com"> 源代码网推荐 设为首页 源代码网推荐 <a onclick="this.style.behavior="url(#default#homepage)";this.sethomepage("http://086net.com");"href="#">设为首页 源代码网推荐 收藏本站 源代码网推荐 <a href="javascript:window.external.addfavorite("http://086net.com","[未名码头]")">收藏本站 源代码网推荐 加入频道 源代码网推荐 <a href="javascript:window.external.addchannel("http://086net.com")">加入频道 源代码网推荐 源代码网推荐 ◇[DELPHI]文本编辑相关 源代码网推荐 checkbox1.checked:=not checkbox1.checked; 源代码网推荐 if checkbox1.checked then richedit1.font.style:=richedit1.font.style [fsBold] else richedit1.font.style:=richedit1.font.style-[fsBold]//粗体 源代码网推荐 if checkbox1.checked then richedit1.font.style:=richedit1.font.style [fsItalic] else richedit1.font.style:=richedit1.font.style-[fsItalic]//斜体 源代码网推荐 if checkbox1.checked then richedit1.font.style:=richedit1.font.style [fsUnderline] else richedit1.font.style:=richedit1.font.style-[fsUnderline]//下划线 源代码网推荐 memo1.alignment:=taLeftJustify;//居左 源代码网推荐 memo1.alignment:=taRightJustify;//居右 源代码网推荐 memo1.alignment:=taCenter;//居中 源代码网推荐 源代码网推荐 ◇[DELPHI]随机产生文本色 源代码网推荐 randomize;//随机种子 源代码网推荐 memo1.font.color:=rgb(random(255),random(255),random(255)); 源代码网推荐 源代码网推荐 ◇[DELPHI]DELPHI5 UPDATE升级补丁序列号 源代码网推荐 1000003185 源代码网推荐 90X25fx0 源代码网推荐 源代码网推荐 ◇[DELPHI]文件名的非法字符过滤 源代码网推荐 for i:=1 to length(s) do 源代码网推荐 if s[i] in ["","/",":","*","?","<",">","|"] then 源代码网推荐 源代码网推荐 ◇[DELPHI]转换函数的定义及说明 源代码网推荐 datetimetofiledate (datetime:Tdatetime):longint; 将Tdatetime格式的日期时间值转换成DOS格式的日期时间值 源代码网推荐 datetimetostr (datetime:Tdatetime):string; 将Tdatatime格式变量转换成字符串,如果datetime参数不包含日期值,返回字符串日期显示成为00/00/00,如果datetime参数中没有时间值,返回字符串中的时间部分显示成为00:00:00 AM 源代码网推荐 datetimetostring (var result string; 源代码网推荐 const format:string; 源代码网推荐 datetime:Tdatetime); 根据给定的格式字符串转换时间和日期值,result为结果字符串,format为转换格式字符串,datetime为日期时间值 源代码网推荐 datetostr (date:Tdatetime) 使用shortdateformat全局变量定义的格式字符串将date参数转换成对应的字符串 源代码网推荐 floattodecimal (var result:Tfloatrec;value: 源代码网推荐 extended;precision,decimals: 源代码网推荐 integer); 将浮点数转换成十进制表示 源代码网推荐 floattostr (value:extended):string 将浮点数value转换成字符串格式,该转换使用普通数字格式,转换的有效位数为15位。 源代码网推荐 floattotext (buffer:pchar;value:extended; 源代码网推荐 format:Tfloatformat;precision, 源代码网推荐 digits:integer):integer; 用给定的格式、精度和小数将浮点值value转换成十进制表示形式,转换结果存放于buffer参数中,函数返回值为存储到buffer中的字符位数,buffer是非0结果的字符串缓冲区。 源代码网推荐 floattotextfmt (buffer:pchar;value:extended; 源代码网推荐 format:pchar):integer 用给定的格式将浮点值value转换成十进制表示形式,转换结果存放于buffer参数中,函数返回值为存储到buffer中的字符位数。 源代码网推荐 inttohex (value:longint;digits:integer): 源代码网推荐 string; 将给定的数值value转换成十六进制的字符串。参数digits给出转换结果字符串包含的数字位数。 源代码网推荐 inttostr (value:longint):string 将整数转换成十进制形式字符串 源代码网推荐 strtodate (const S:string):Tdatetime 将字符串转换成日期值,S必须包含一个合法的格式日期的字符串。 源代码网推荐 strtodatetime (const S:string):Tdatetime 将字符串S转换成日期时间格式,S必须具有MM/DD/YY HH:MM:SS[AM|PM]格式,其中日期和时间分隔符与系统时期时间常量设置相关。如果没有指定AM或PM信息,表示使用24小时制。 源代码网推荐 strtofloat (const S:string):extended; 将给定的字符串转换成浮点数,字符串具有如下格式: 源代码网推荐 [ |-]nnn…[.]nnn…[< |-><E|e>< |->nnnn] 源代码网推荐 strtoint (const S:string):longint 将数字字符串转换成整数,字符串可以是十进制或十六进制格式,如果字符串不是一个合法的数字字符串,系统发生ECONVERTERROR异常 源代码网推荐 strtointdef (const S:string;default: 源代码网推荐 longint):longint; 将字符串S转换成数字,如果不能将S转换成数字,strtointdef函数返回参数default的值。 源代码网推荐 strtotime (const S:string):Tdatetime 将字符串S转换成TDATETIME值,S具有HH:MM:SS[AM|PM]格式,实际的格式与系统的时间相关的全局变量有关。 源代码网推荐 timetostr (time:Tdatetime):string; 将参数TIME转换成字符串。转换结果字符串的格式与系统的时间相关常量的设置有关。 源代码网推荐 源代码网推荐 ◇[DELPHI]程序不出现在ALT CTRL DEL 源代码网推荐 在implementation后添加声明: 源代码网推荐 function RegisterServiceProcess(dwProcessID, dwType: Integer): Integer; stdcall; external "KERNEL32.DLL"; 源代码网推荐 RegisterServiceProcess(GetCurrentProcessID, 1);//隐藏 源代码网推荐 RegisterServiceProcess(GetCurrentProcessID, 0);//显示 源代码网推荐 用ALT DEL CTRL看不见 源代码网推荐 源代码网推荐 ◇[DELPHI]程序不出现在任务栏 源代码网推荐 uses windows 源代码网推荐 var 源代码网推荐 ExtendedStyle : Integer; 源代码网推荐 begin 源代码网推荐 Application.Initialize; 源代码网推荐 源代码网供稿. |
