Delphi: why breakpoints from time to time are not usable (green highlighted line on IDE)?

Debug info isn’t present in the file. Make sure that you’re using the Debug configuration. (Project Manager tree, expand Build Configurations, make sure Debug is bold. If it’s not, right click Debug and choose Activate from the context menu.) Make sure you then do a Build of your project, not just a Compile. If that … Read more

Which is preferable: Free or FreeAndNil?

See delphibasics-FreeAndNil docwiki.embarcadero-FreeAndNil pages-freeandnil [Broken] eurekalog-freeandnil blogs.embarcadero (via Wayback Machine) … And have a look at the implementation: procedure FreeAndNil(var Obj); var Temp: TObject; begin Temp := TObject(Obj); Pointer(Obj) := nil; Temp.Free; end; Examples Consider the following code: procedure TForm1.FormCreate(Sender: TObject); var bm: TBitmap; begin bm := TBitmap.Create; bm.LoadFromFile(‘C:\Users\Andreas Rejbrand\Documents\RAD Studio\6.0\Demos\DelphiWin32\VCLWin32\Football\up.bmp’); bm.Free; if Assigned(bm) then … Read more

Using Case Statement with String

In Jcl library you have the StrIndex function StrIndex(Index, Array Of String) which works like this: Case StrIndex(‘SomeName’, [‘bobby’, ‘tommy’, ‘somename’]) of 0: ..code.. ;//bobby 1: ..code..;//tommy 2: ..code..;//somename else ShowMessage(‘error’); end.

How do I make a PNG resource?

Example text file (named myres.rc): MYPNG RCDATA mypng.png Added to project: {$R ‘myres.res’ ‘myres.rc’} Example of loading at runtime: uses PngImage; var Png: TPngImage; begin Png := TPngImage.Create; try Png.LoadFromResourceName(HInstance, ‘MYPNG’); Image1.Picture.Graphic := Png; // Image1: TImage on the form finally Png.Free; end; end;

Delphi: Prompt for UAC elevation when needed

i would relaunch yourself as elevated, passing command line parameters indicating what elevated thing you want to do. You can then jump right to the appropriate form, or just save your HKLM stuff. function RunAsAdmin(hWnd: HWND; filename: string; Parameters: string): Boolean; { See Step 3: Redesign for UAC Compatibility (UAC) http://msdn.microsoft.com/en-us/library/bb756922.aspx This code is released … Read more

How to determine Delphi Application Version

Here is how I do it. I put this in almost all of my small utilities: procedure GetBuildInfo(var V1, V2, V3, V4: word); var VerInfoSize, VerValueSize, Dummy: DWORD; VerInfo: Pointer; VerValue: PVSFixedFileInfo; begin VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy); if VerInfoSize > 0 then begin GetMem(VerInfo, VerInfoSize); try if GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo) then begin VerQueryValue(VerInfo, ‘\’, … Read more

Delphi: Understanding constructors

I see two reasons your original set of declarations shouldn’t compile cleanly: There should be a warning in TCellPhone that its constructor hides the method of the base class. This is because the base-class method is virtual, and the compiler worries that you’re introducing a new method with the same name without overriding the base-class … Read more