Format('%0.2d',[1] = '01'; //2表示两位 // formatdatetime('aaa',now;//当前星期 formatdatetime('c',now;//以2003-8-16 23:03:23的形式显示当前日期和时间 formatdatetime('d',now;//显示当前的日期 1被显示成1 formatdatetime('dd',now;//显示当前的日期 1被显示成01 formatdatetime('ddd',now;//显示当前的星期 formatdatetime('ddddd',now;//以2003-8-1的形式显示年月日 formatdatetime('dddddd',now;//以2003年8月1日的形式显示年月日 formatdatetime('dddddd ddd',now;//以‘2003年8月1日 星期五’的形式显示年月日及星期 formatdatetime('e',now;//显示年的最后一位2003被显示成3 formatdatetime('ee',now;//显示年的最后二位2003被显示成03 formatdatetime('eee',now;//显示年2003被显示成2003 formatdatetime('h',now;//显示小时1被显示成1 formatdatetime('hh',now;//显示小时1被显示成01 formatdatetime('m',now;//显示月1被显示成1 formatdatetime('mm',now;//显示月1被显示成01 formatdatetime('mmm',now;//以‘八月’的形式显示月份 formatdatetime('n',now;//显示当前分钟1被显示成1 formatdatetime('nn',now;//显示当前分钟1被显示成01 formatdatetime('s',now;//显示当前秒1被显示成1 formatdatetime('ss',now;//显示当前秒1被显示成01 formatdatetime('t',now;//以1:05的形式显示小时和分钟 formatdatetime('tt',now;//以1:06:13的形式显示小时和分钟和秒 formatdatetime('y',now;////显示年的最后二位2003被显示成03 formatda
tetime('yyy',now;//显示年2003被显示成2003 formatdatetime('z',now;//显示当前毫秒1被显示成1 formatdatetime('zz',now;//显示当前毫秒1被显示成01 formatdatetime('zzz',now;//显示当前毫秒1被显示成001 除上面之外的字母或字符就直接显示。 以上在控制面板里的选项:时间格式H:mm:ss日期格式yyyy-M-d区域选项:中文(中国) 在控制面板里“时间区域”选项里选择的时间或日期选项不同,显示结果可能会有所不同。 2003/9/6 (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('m
dg'.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.Butto
n1Click(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; adoconnecti
on1.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;U
se 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; end; except ShowMessage('???′꧰ü'; Exit; end; end; Application.MessageBox('1§?2?ú£?êy?Y???′3é1|','ìáê?',MB_OK + MB_ICONINFORMATION; end; (9.查局域网上的sqlserver报务器。 uses Comobj; procedure TForm1.Button1Click(Sender: TObject; var SQLServer:Variant; ServerList:Variant; i,nServers:integer; sRetValue:String; begin SQLServer := CreateOleObject('SQLDMO.Application'; ServerList:= SQLServer.ListAvailableSQLServers; nServers:=ServerList.Count; for i := 1 to nservers do ListBox1.Items.Add(ServerList.Item(i; SQLServer:=NULL; serverList:=NULL; end; (10.窗体打开时的淡入效果。 procedure TForm1.FormCreate(Sender: TObject; begin AnimateWindow (Handle, 400, AW_CENTER; end; (11.动态创建窗体。 procedure TForm1.Button1Click(Sender: TObject; begin try form2:=Tform2.Create(self; form2.ShowModal; finally form2.Free; end; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction; begin action:=cafree; end; procedure TForm1.FormDest
roy(Sender: TObject; begin form1:=nil; end; (12.复制文件。 procedure TForm1.Button1Click(Sender: TObject; begin try copyfileA(pchar('C:\',pchar('D:\',false; except showmessage('sfdsdf'; end; end; (13.复制文件夹。 uses shellAPI; procedure TForm1.Button1Click(Sender: TObject; var lpFileOp: TSHFileOpStruct; begin with lpFileOp do begin Wnd:=Self.Handle; wfunc:=FO_COPY; pFrom:=pchar('C:\AAA'; pTo:=pchar('D:\AAA'; fFlags:=FOF_ALLOWUNDO; hNameMappings:=nil; lpszProgressTitle:=nil; fAnyOperationsAborted:=True; end; if SHFileOperation(lpFileOp<>0 then ShowMessage('删除失败'; end; (14.改变Dbgrid的选定。 procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState; begin if gdSelected in state then SetBkColor(dbgrid1.canvas.handle,clgreen else setbkcolor(dbgrid1.canvas.handle,clwhite; dbgrid1.Canv
as.TextRect(rect,0,0,field.AsString; dbgrid1.Canvas.Textout(rect.Left,rect.Top,field.AsString; end; (15.检测系统是否已安装了ADO。 uses registry; function Tform1.ADOInstalled:Boolea
n; var r:TRegistry; s:string; begin r := ate; try with r do begin RootKey := HKEY_CLASSES_ROOT; OpenKey( '\ADODB.Connection\CurVer', false ; s := ReadString(''; if s <> '' then Result := True else Result := False; CloseKey; end; finally r.free; end; end; procedure TForm1.Button1Click(Sender: TObject; begin if ADOInstalled then showmessage('this computer has installed ADO'; end; (16.取利主机的ip地址。 uses winsock; procedure TForm1.Button1Click(Sender: TObject; var IP:string; IPstr:String; buffer:array[1..32] of char; i:integer; WSData:TWSAdata; Host:PHostEnt; begin if WSAstartup(2,WSData<>0 then begin showmessage('WS2_32.DLL3?ê??ˉ꧰ü.'; exit; end; try if GetHostname(@buffer[1],32<>0 then begin showmessage('??óDμ?μ??÷?ú??.'; exit; end; except showmessage('??óD3é1|·μ???÷?ú??'; exit; end; Host:=GetHostbyname(@buffer[1]; if Host=nil then begin showmessage('IPμ??·?a??.'; exit; end else begin edit2.Text:=Host.h_name; edit3.Text:=chr(host.h_addrtype+64; for i:=1 to 4 do begin IP:=inttostr(ord(host.h_addr^[i-1]; if i<4 then ipstr:=ipstr+IP+'.' else edit1.Text:=ipstr+ip; end; end; WSACleanup; end; (17.取得计算机名。 _name:string; var ComputerName: PChar; size: DWord; begin GetMem(Comput
erName,255; size:=255; if GetComputerName(ComputerName,size=False then result:='' else result:=ComputerName; FreeMem(ComputerName; end; procedure TForm1.Button1Click(Sender: TObject; begin label1.Caption:=get_name; end; (18.取得硬盘序列号。 function tform1.GetHDSerialNumber: LongInt; {$IFDEF WIN32} var pdw : pDWord; mc, fl : dword; {$ENDIF} begin {$IfDef WIN32} New(pdw; GetVolumeInformation('c:\',nil,0,pdw,mc,fl,nil,0; Result := pdw^; dispose(pdw; {$ELSE} Result := GetWinFlags; {$ENDIF} end; procedure TForm1.Button1Click(Sender: TObject; begin edit1.Text:=inttostr(gethdserialnumber; end; (19.限定光标移动范围。 procedure TForm1.Button1Click(Sender: TObject; var rect1:trect; begin re
ct1:=button2.BoundsRect; mapwindowpoints(handle,0,rect1,2; clipcursor(@rect1; end; procedure TForm1.Button2Click(Sender: TObject; var screenrect:trect; begin screenrect:=rect(0,0,screen.Width,screen.Height; clipcursor(@screenrect; end; (20.限制edit框只能输入数字。 procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char; begin if not (key in ['0'..'9','.',#8] then begin key:=#0; Messagebeep(0; end; end; (21.dbgrid中根据任一条件某一格变。 procedure TForm_main.DBGridEh1DrawColumnCell(Sender:
TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState; begin if (trim(DataModule1.ADOQuery1.FieldByName('dczt'.AsString='OK' then begin if datacol=6 then begin DbGrideh1.Canvas.Brush.Color:=clGradientActiveCaption; DbGrideh1.DefaultDrawColumnCell(Rect,datacol,column,state; end; end; end; (22.打开word文件。 procedure TfjfsglForm.SpeedButton4Click(Sender: TObject; var MSWord: Variant; str:string; begin if trim(DataModule1.adoquery27.fieldbyname('fjmc'.asstring<>'' then begin str:=trim(DataModule1.ADOQuery27.fieldbyname('fjmc'.AsString; MSWord:= CreateOLEObject('Word.Application';// MSWord.Documents.Open('d:\Program Files\Common Files\Sfa\'+str, True;// MSWord.Visible:=1;// str:=''; MSWord.ActiveDocument.Range(0, 0;// MSWord.ActiveDocument.Range.InsertAfter(str;//?úWord?D???ó×?·?'Title' MSWord.ActiveDocument.Range.InsertParagraphAfter; end else showmessage(''; end; (23.word文件传入和传出数据库。 uses IdGlobal; procedure TdjhyForm.SpeedButton2Click(Sender: TObject; var sfilename:string; function BlobContentTostring(const Filename:string:string; begin with Tfilestream.Create(filename,f
mopenread do try setlength(result,size; read(pointer(result^,size; finally free; end; end; begin if opendialog1.Execute then begin sfilename:=opendialog1.FileName; DataModule1.ADOQuery14.Edit; DataModule1.ADOQuery14.FieldByName('word'.AsString:=blobcontenttostring(sfilename; DataModule1.ADOQuery14.Post; end; end; procedure TdjhyForm.SpeedButton1Click(Sender: TObject; var sfilename:string; bs:Tadoblobstream; begin bs:=Tadoblobstream.Create(TBLOBfield(DataModule1.ADOQuery14.FieldByName('word',bmread; try sfilename:=extractfilepath(application.ExeName+trim(DataModule1.adoquery14.fieldbyname('hybh'.AsString; sfilename:=sfilename+'.'+'doc'; bs.SaveToFile(sfilename; try djhyopenform:=Td
>c++trunc函数
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论