| r.yahoo.com/Computers_and_Internet/Programming_and_Development/Languages/Delphi/
删掉程序自己的exe文件 procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); var F:TextFile; begin AssignFile(F,''''delself.bat''''); Rewrite(F);{F为TextFile类型} WriteLn(F,''''del ''''+ExtractFileName(Application.ExeName)); WriteLn(F,''''del %0''''); //删除自己delself.bat CloseFile(F); WinExec(''''delself.bat'''',SW_HIDE); end;
if ord(s[9])>128 then ShowMessage(''''该位置字符是汉字''''); 汉字是双字节的 更改系统时间格式:
var str: string; begin str := ''''yyyy-mm-dd''''; if SetLocaleInfoa(LOCALE_SYSTEM_DEFAULT, LOCALE_SLONGDATE, PChar(str)) then begin showmessage(''''更改日期格式成功''''); end; end;
休息一分钟: var I:integer; begin i:=gettickcount; while (Gettickcount-i)<=10000 do application.ProcessMessages;//保证消息循环 end;
取主文件名: function retuFileName(const FileName: string): string; var I: Integer; begin I := LastDelimiter(''''.'''', FileName); Result := Copy(FileName, 1, i-1);
end;
(1).按下ctrl和其它键之后发生一事件。 procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (ssCtrl in Shift) and (key =67) then showmessage(''''keydown Ctrl+C''''); end; (2).Dbgrid中用Enter键代替Tab键. procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then if ActiveControl = DBGrid1 then begin TDBGrid(ActiveControl).SelectedIndex := TDBGrid(ActiveControl).SelectedIndex + 1; Key := #0; end; end; (3).Dbgrid中选择多行发生一事件。 procedure TForm1.Button1Click(Sender: TObject); var i:integer; bookmarklist:Tbookmarklist; bookmark:tbookmarkstr; begin bookmark:=adoquery1.Bookmark; bookmarklist:=dbgrid1.SelectedRows; try begin for i:=0 to bookmarklist.Count-1 do begin adoquery1.Bookmark:=bookmarklist[i]; with adoquery1 do begin edit; fieldbyname(''''mdg'''').AsString:=edit2.Text; post; end; end; end; finally adoquery1.Bookmark:=bookmark; end; end; (4).Form的一个出现效果。 procedure TForm1.Button1Click(Sender: TObject); var r:thandle; i:integer; begin for i:=1 to trunc(width/1.414) do begin r:=CreateEllipticRgn(trunc(width/2)-i,trunc(height/2)-i,trunc(width/2)+i,trunc(height/2)+i); SetWindowRgn(handle,r,true); Application.ProcessMessages; sleep(1); end; end; (5).用Enter代替Tab在编辑框中移动隹点。 procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin if not (Activecontrol is Tmemo) then begin key:=#0; keybd_event(vk_tab,mapvirtualkey(vk_tab,0),0,0); end; end; end; (6).Progressbar加上色彩。 const {$EXTERNALSYM PBS_MARQUEE} PBS_MARQUEE = 08; var Form1: TForm1; implementation {$R *.dfm} uses CommCtrl; procedure TForm1.Button1Click(Sender: TObject); begin // Set the Background color to teal Progressbar1.Brush.Color := clTeal; // Set bar color to yellow SendMessage(ProgressBar1.Handle, PBM_SETBARCOLOR, 0, clYellow); end; (7).住点移动时编辑框色彩不同。 procedure TForm1.Edit1Enter(Sender: TObject); begin (sender as tedit).Color:=clred; end; procedure TForm1.Edit1Exit(Sender: TObject); begin (sender as tedit).Color:=clwhite; end; (8).备份和恢复 procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog1.Execute then begin try adoconnection1.Connected:=False; adoconnection1.ConnectionString:=''''Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=FRIEND-YOFZKSCO;''''+ ''''Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=FRIEND-YOFZKSCO;Use Encryption for Data=False;Tag with column collation when possible=False''''; adoconnection1.Connected:=True; with adoQuery1 do begin Close; SQL.Clear; SQL.Add(''''Backup DataBase sfa to disk =''''''''''''+opendialog1.FileName+''''''''''''''''); ExecSQL; end; except ShowMessage(''''±?·Yê§°ü''''); Exit; end; end; Application.MessageBox(''''1§?2?ú£?êy?Y±?·Y3é1|'''',''''ìáê?'''',MB_OK + MB_ICONINFORMATION); end; procedure TForm1.Button2Click(Sender: TObject); begin if OpenDialog1.Execute then begin try adoconnection1.Connected:=false; adoconnection1.ConnectionString:=''''Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=FRIEND-YOFZKSCO;''''+ ''''Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=FRIEND-YOFZKSCO;Use Encryption for Data=False;Tag with column collation when possible=False''''; adoconnection1.Connected:=true; with adoQuery1 do begin Close; SQL.Clear; SQL.Add(''''Restore DataBase sfa from disk =''''''''''''+opendialog1.FileName+''''''''''''''''); ExecSQL;   上一页 [1] [2] [3] [4] [5] [6] [7] 下一页 |