Identifiers for Delphi’s $WARN compiler directive

Darian’s right that the DCCStrs.pas lists the identifiers used by the Delphi compiler. It hadn’t occurred to me to search the source, since Delphi doesn’t include the source to its compiler. I’ve extracted the identifiers for hints and warnings from that file: {$WARN ASG_TO_TYPED_CONST OFF} {$WARN BAD_GLOBAL_SYMBOL OFF} {$WARN BOUNDS_ERROR OFF} {$WARN CASE_LABEL_RANGE OFF} {$WARN … 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

Delphi: What is Application.Handle?

The reason for the application window has a bit of a sordid history. When developing Delphi 1, we knew we wanted to use “SDI” (windows scattered all over the desktop) ui model for the IDE. We also knew that Windows sucked (and still does) at that model. However we also noticed that Visual Basic at … Read more

How to make TRichEdit behave like WordPad on Windows 7 when changing font for certain non-text characters?

One thing to check would be to see if the richedit controls used by WordPad and TRichEdit are the same. I would recommend you check with (Spy++) Spyxx.exe to make sure the control has the same class and the same styles. If they are the same, I would then also check to make sure the … Read more

What’s the difference between Refresh, Update and Repaint?

According to the online documentation: Refresh – Repaints the control on the screen. Call Refresh method to repaint the control immediately. Refresh calls the Repaint method. Use the Refresh and Repaint methods interchangeably. Repaint – Forces the control to repaint its image on the screen. Call Repaint to force the control to repaint its image … Read more

How to get the Memory Used by a Delphi Program

You can get useful memory usage information out of the Delphi runtime without using any direct Win32 calls: unit X; uses FastMM4; //include this or method will return 0. …. function GetMemoryUsed: UInt64; var st: TMemoryManagerState; sb: TSmallBlockTypeState; begin GetMemoryManagerState(st); result := st.TotalAllocatedMediumBlockSize + st.TotalAllocatedLargeBlockSize; for sb in st.SmallBlockTypeStates do begin result := result + … Read more

Is COM broken in XE2, and how might I work around it?

Workaround rowCnt := UsedRange.Rows.Count; colCnt := UsedRange.Columns.Count; for Row := 1 to rowCnt do begin for Col := 1 to colCnt do begin v := UsedRange.Item[Row, Col].Value; end; end; This also works (and may help you find a workaround in more complicated use cases): function ColCount(const range: ExcelRange): integer; begin Result := range.Columns.Count; end; for … Read more

Profiler and Memory Analysis Tools for Delphi [closed]

For the price, you cannot beat FastMM4 as a memory tracker. It’s simple to use yet powerful and well integrated with Delphi. I guess that you know that, without downloading, installing or changing anything else, just putting this line ReportMemoryLeaksOnShutDown := True; anywhere in your code, will enable basic reporting of memory leaks. If you … Read more

Delphi 2006-2010 error: “Cannot create file C:\Users\Admin\AppData\Local\Temp\EditorLineEnds.ttr”

There are three solutions to this that I am aware of: Try uninstalling the Windows security update KB2982791 which was already mentioned by Francisco Caffagni. This solved the issue for me (Windows 8.1 + Delphi 2007) but it might not be such a good idea to uninstall a Windows security update. Rename the file every … Read more