Delphi Programming Experience (ZZ)

xiaoxiao2021-03-06  52

I have made a small summary of some of the previous Delphi programming experience. After the summary, I have a summary of this idea: If I send these summarizes to the online Delphi friends, if they also have some Delphi programming, also Give me (if you wish), this makes everyone will definitely be very fast. I email: YesterDay97@hotmail.com

(1). A event after the Ctrl and other keys are pressed. 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 Tab key instead of the Enter key using 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). Select Multi-line events in. 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). A appearance effect of form. Procedure TForm1.Button1Click (Sender: TOBJECT); VAR R: THANDLE; I: Integer; Begin for i: = 1 to trunc (width / 1.414) Do Begin R: = CreatellipticRgn (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) . Use Enter instead of TAB to move in the edit box.

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 plus color. 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). Edit box color when the point is moving. Procedure tform1.edit1enter (sender: TOBJECT); Begin (Sender as tedit) .COLOR: = CLRED; end; procedure tform1.edit1exit (sender: TObject); recomcolor: = CLWHITE; END; (8) ) backup and recovery 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; InitialCatalog = 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 disk = '' ' opendialog1.FileName ' sfa to '' '); EXECSQL; End; Except ShowMessage (' ±? · Yê§ ° ü '); exit; end; end; application.MessageBox (' 1 §? 2? Ú? Ê ê 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; InitialCatalog = 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; End; Except ShowMessage (' ??? 'ê§ ° ü'); exit; end; end; application.MessageBox ('1 §? 2? Ú? Êy? Y ???' 3é1 | ',' ìáê? ', MB_OK MB_ICONITIONS; END;

9) Find the SQLServer server on the LAN. 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; Nserve: = ServerList.count; for i: = 1 to Nserve do listbox1.items.add (ServerList.Item (i)); SQLServer: = null; serverList: = null; end; (10). Form opening The fade in the fade. Procedure TForm1.FormCreate (Sender: TOBJECT); Begin AnimateWindow (Handle, 400, AW_Center); END; (11). Dynamically create forms. 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.formDestroy (Sender: TOBJECT); begin form1: = nil; end; (12). Copy file. Procedure tForm1.Button1Click (Sender: Tobject); Begin Try Copyfilea (Pchar ('C: /AAA.TXT'), PCHAR ('D: /AAA.TXT'), FALSE); Except ShowMessage ('sfdsdf'); END ; End; (13). Copy the folder.

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 ( 'delete failed'); End; (14). Change the selected color of 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.canvas.TextRect (Rect, 0, 0, Field.Asstring); dbgrid1.canvas.textout (Rect.Lect, Rect.top, Field.Asstring); END; (15). Detection system has installed ADO . uses registry; function Tform1.ADOInstalled: Boolean; var r: TRegistry; s: string; begin r: = TRegistry.create; 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 The ShowMessage ('this Computer Has Installed Ado'); END; (16). The IP address of the peeling host.

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 SHOWMESAGE '?? ódμ? μ? ÷? ú ??.'); exit; end; Except showMessage ('?? ód3é1 | · μ ??? ÷? ú ??'); exit; end; host: = gethostbyname (@Buffer [1]); if Host = nil the beginning ('ipμ ?????.'); exit; end else begin edit2.text: = host.h_name; edit3.text: = CHR ( Host.h_addrtype 64); for i: = 1 to 4 do begin ip: = INTOSTR (ORD (Host.h_addr ^ [i-1])); IF i <4 Then Ipstr: = IPSTR IP '.' Else Edit1.text: = IPSTR IP; End; End; wsacleanup; end; (17). A computer name. function tform1.get_name: string; var ComputerName: PChar; size: DWord; begin GetMem (ComputerName, 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). Get the hard disk serial number. 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: = INTOSTR (GETHDSERIALNUMBER); END; (19). Limit the cursor mobile range. procedure TForm1.Button1Click (Sender: TObject); var rect1: trect; begin rect1: = 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). Restricting the Edit box can only enter numbers. Procedure TForm 1.EDit1KeyPress (Sender: Tobject; Var Key: Char); Begin if Not (Key In ['0' .. '9', '.', # 8]) The begin key: = # 0; MessageBeep (0 ); END; END; (21). DBGRID is discolored according to any one of the qualifications. 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) open word file.

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 / commun 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 file incoming and outgoing database.

uses IdGlobal; procedure TdjhyForm.SpeedButton2Click (Sender: TObject); var sfilename: string; function BlobContentTostring (const Filename: string): string; begin with Tfilestream.Create (filename, fmopenread) 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: = Tdjhyopenform.Create (self); djhyopenform.olecontainer1.CreateObjectFromFile (sfilename, false); djhyopenform.OleContainer1.Iconic: = true; djhyopenform.ShowModal; finally djhyopenform.Free; end; finally BS.FREE; END; END; (24). Tips for the Chinese title. Procedure Tdjhyform.SpeedButton5Click (Sender: Tobject); Begin if Application.MessageBox ('', MB_YESNO MB_ICONWARNING) = ID_YES THEN DATAMODULE1.ADOQUERY14.DELETE; END; (25). Run an application file.

转载请注明原文地址:https://www.9cbs.com/read-115633.html

New Post(0)