| « | January 2026 | » | | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | |
| 公告 |
| 暂无公告... |
| Blog信息 |
|
blog名称:DeathCat的猫窝 日志总数:17 评论数量:89 留言数量:0 访问次数:218898 建立时间:2005年4月5日 |

| |
|
[Delphi食堂]还有还有 某位虾客的学习笔记~~ 网上资源, 软件技术
DeathCat 发表于 2005/4/6 11:46:02 |
| 某位虾客的学习笔记~~大名我就不公布啦
不过都是些很有用的咚咚
×调用EXCLE打开文件。USES SHELLAPIShellexecute(handle,nil,pchar('c:\报表.xls'),nil,nil,sw_shownormal);
◇[DELPHI]关于处理注册表uses Registry;var reg:Tregistry;reg:=Tregistry.create;reg.rootkey:='HKey_Current_User';reg.openkey('Control Panel\Desktop',false);reg.WriteString('Title Wallpaper','0');reg.writeString('Wallpaper',filelistbox1.filename);reg.closereg;reg.free;
×报错函数procedure ErrMsg(sMsg:String; sPrompt:String='出错信息');//出错信息显示框begin Application.MessageBox(PChar(sMsg), PChar(sPrompt), MB_IConERROR or MB_OK)end;×出错信息 try except on E: Exception do begin ErrMsg(Format('登录[%s]数据库失败,回退操作将失效;'#13#10, [Server]) + E.Message); Result := False; end; end;
×中文提示框Application.MessageBox('无法打开指定文件', '提示', MB_OK);
×转换时间的函数formatdatetime('yyyy"年"mm"月"dd"日"', UnccSysDate);UnccSysDate 为TDATATIME类型
×定死小数点后的位数Format('%*.*n', [10, 2, FieldByName('syje').AsFloat]
×类型转换函数 inttostr(); 将数字转换为字符串 Ord(); 返回一个字符的序号(ASCII码) Char(); 把一个整型数转化成相应序号的字符 UpCase(); 把小写转化为大写
×字符串处理函数 concat(); 与(+)功能相同,将多个字符串组合在一起 copy(); 会返回一个字符串中的子字符串 delete(); 在一个字符串中从一个指定位置起删除一定数字的字符() insert(); 在一个字符串中插入一个字符串 length(); 返回字符串的长度 pos(); 返回一个子字符串在一个字符串中的位置
载入文件的实现方法×var ts:tstring; begin ts:tstinglist.creat; ts.loadfromfile('文件的绝对路径'); //调用文件
×文件夹操作uses filectrl;procedure ForceDirectorys(dir:string) //一次建立指定的多级文件夹function DirectoryExists(Name: string): Boolean; // 指定文件夹是否存在function SelectDirectory(var Directory: string; Options: TSelectDirOpts; HelpCtx: Longint):Boolean; // 打开一个选择文件夹的对话框(英文的)
×var mytextfile:textfile; begin assignfile(mytextfile,'mytextfile.exe');reset(mytextfile);//rewrite()创建并打开文件(已有就覆盖),reset()以只读方式打开文件,append()以追加方式打开文件;try //可以加一句while nit eof(mytextfile) do; { //操作文件 for i:=1 to 5 do begin s:='This is line #'; writeln(mytextfile,s,i);//结果被创建的文件中包含 this is line # 1……this is line # 5 //writeln()为往指定文件中写东西,还有readln(mytextfile,s,i)从指定的文件中读数据; end; } finally closefile(mytextfile); end;end;
×edit只能接收数字 procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); beginif ((Key < '0') or (Key > '9')) then Key := Chr(0);end;
×创建路径USES FileCtrl;if not DirectoryExists(ExtractFilePath(paramstr(0)) + 'ElectronicBill\') then CreateDir(ExtractFilePath(paramstr(0)) + 'ElectronicBill\');fileexists();判断文件是否存在。 ×选择一个路径 USES FileCtrl; SelectDirectory('请选择存储路径!', '我的电脑', sSavePath);
◇[DELPHI]网络邻居复制文件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_MACHINE\Software\Microsoft\Windows\CurrentVersionSystemRoot键,取得如: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),trunc(y));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:\abc\a.txt','x.abc','c:\abc\',0);ExecuteFile('http://tingweb.yeah.net','','',0);ExecuteFile('mailto:tingweb@wx88.net','','',0);
关于键盘常量名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_DOWNF1--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.
增加到文档菜单连接uses shellapi,shlOBJ;shAddToRecentDocs(shArd_path,pchar(filepath));//增加连接shAddToRecentDocs(shArd_path,nil);//清空
判断鼠标按键if GetAsyncKeyState(VK_LButton)<>0 then ... //左键if GetAsyncKeyState(VK_MButton)<>0 then ... //中键if GetAsyncKeyState(VK_RButton)<>0 then ... //右键
按键接受消息OnCreate事件中处理:Application.OnMessage:=MyOnMessage;procedure Tform1.MyOnMessage(var MSG:TMSG;var Handle:Boolean);beginif msg.message=256 then ... //ANY键if msg.message=112 then ... //F1if msg.message=113 then ... //F2end;
隐藏共享文件夹共享效果:可访问,但不可见(在资源管理、网络邻居中)取共享名为:direction$访问://computer/dirction/
|
|
|