1. If you want your program to handle exceptions correctly, please quote the SysUtils.pas unit, otherwise even if the program uses try. . . except. . . Exceptions are also not caught correctly. 2. A way to define a constant string resourcestring aa='aaaa';raise Exception.CreateRes(@aa); 3. Initialization of string constant array const constarray:array [0..2] of string=('first ','second','third');4. Structure initialization type Tstructinit=record A1:integer; A2:array [0..2] of integer;End;Const m_structinit:Tstructinit=(A1:0;A2:(0,1,2));5. The length of the multidimensional array var array2:array of array of integer;setlength(array2,2,2);6 . The space opened using Create and New exists in the heap and cannot be automatically released. It is recommended to use FreeAndNil to release. Parameters and local variables exist in the stack and are automatically released. 7. SizeOf is not suitable for objects and always returns 4; it can be returned correctly for fixed types. 8. Create(nil) needs to be released manually, and Create(self) will be released as the owner releases. 9. Dynamic changes have been Define the value of the constant PRocedure ChangeConst(const Const;var Value;Size:Integer);begin Move((@Value)^,(@Constant)^,Size);End;10. Using DownTo in a loop when performing a deletion operation will avoid errors. 11. The Ascii code of Chinese characters is >128, which can be used to determine whether it is a Chinese character. 12. When writing a dll, you need to use the Sharemem unit to reference BORLANDMM.DLL memory management. 13. PostMessage only puts the message in the message queue and needs to be queued for processing. SendMessage bypasses the message queue and is sent directly to the window procedure, and does not return until the message processing return value. 14. Mouse movement in and out messages: CM_MOUSEENTER, CM_MOUSELEAVE15. Shutdown message WM_QUERYENDsession16. You can use ThintWindow and the class method ActivateHint to create a floating form.17. Bring up the file properties dialog box uses ShellAPI; function ShowFileProperties(FileName: String; Wnd: lpVerb := PAnsiChar('properties'); lpIDList := nil; lpDirectory := nil; nShow := 0; hInstApp := 0; lpParameters := nil; dwHotKey := 0; hIcon := 0; hkeyClass := 0; hProcess := 0; lpClass := nil; end; Result := ShellExecuteEX(@sfi);end;procedure TForm1.Button1Click(Sender: TObject);begin ShowFileProperties('c:/AA.txt', Handle);end;18. Changing the system time uses Windows,Dialogs,Forms;var MyTime: TsystemTime;begin FillChar(MyTime,sizeof(MyTime),#0); MyTime.wYear:=2003; MyTime.wMonth:=06; MyTime.wDay:=01; If not SetSystem(MyTime) thenShowmessage('Failure'); End; 19. Copy the folder Xcopy. procedure Xcopy(SourceDir,DestinationDir: String);
var
Search: TSearchRec;
Rec: Word;
Begin
SourceDir := SourceDir + '/';
Rec := FindFirst(SourceDir + '*.*', faAnyFile, Search);
While Rec = 0 Do
Begin
If Search.Name[1] <> '.' Then
Begin
If (Search.Attr And faDirectory) = faDirectory Then
Begin
Windows.CreateDirectory(PChar(DestinationDir + '/' + Search.Name), nil);
FileSetAttr(DestinationDir + '/' + Search.Name, FileGetAttr(SourceDir + '/' + Search.Name));
X_Copy(SourceDir + '/' + Search.Name, DestinationDir + '/' + Search.Name);
end
Else
Begin
CopyFile(PChar(SourceDir + '/' + Search.Name),PChar(DestinationDir + '/' + Search.Name), True);
FileSetAttr(DestinationDir + '/' + Search.Name, FileGetAttr(SourceDir + '/' + Search.Name));
application.ProcessMessages;
end;
end;
Rec := FindNext(Search);
end;
FindClose(Search);
end;20. Draw transparent bitmap procedure DrawTrans(DestCanvas: TCanvas; ; ORBitmap:= NIL; try ANDBitmap:= TBitmap.Create; ORBitmap:= TBitmap.Create; Src := Bounds(0,0, SrcBitmap.Width, SrcBitmap.Height); with ORBitmap do begin Width:= SrcBitmap.Width; Height:= SrcBitmap.Height; Canvas.Brush .Color := clBlack; Canvas.CopyMode := cmSrcCopy; Canvas.BrushCopy(Src, SrcBitmap, Src, AColor); end; with ANDBitmap do begin Width:= SrcBitmap.Width; Height:= SrcBitmap.Height; Canvas.Brush.Color := BackColor; Canvas.CopyMode := cmSrcInvert ; Canvas.BrushCopy(Src, SrcBitmap, Src, AColor); end; with DestCanvas do begin CM := CopyMode; CopyMode := cmSrcAnd; Draw(X,Y, ANDBitmap); CopyMode := cmSrcPaint; Draw(X,Y, ORBitmap); CopyMode := CM; end; finally ANDBitmap.Free; ORBitmap.Free; end;end;procedure TForm1.Button4Click(Sender: TObject);begin DrawTrans(Image1.Canvas, 0,0, Image2.Picture.Bitmap, clBlack, clSilver);end;21. Get the CPU speed function GetCpuSpeed: Extended;var t, mhi, mlo, nhi, nlo: dword; shr32 : comp;begin shr32 := 65536; shr32 := shr32 * 65536; t := GetTickCount; while t = GetTickCount do ; asm DB 0FH,031H // rdtsc mov mhi,edx mov mlo,eax end; while GetTickCount < (t + 1000) do ; asm DB 0FH,031H // rdtsc mov nhi,edx mov nlo,eax end; Result := ((nhi * shr32 + nlo) - (mhi * shr32 + mlo)) / 1E6;end;procedure TForm1.Button4Click(Sender: TObject);begin label1.Caption := FloatToStr(GetCpuSpeed) + 'mhz';end; temporarily I just wrote so much, and I will gradually update and add more in the future.