Why can a WideString not be used as a function return value for interop?

In regular Delphi functions, the function return is actually a parameter passed by reference, even though syntactically it looks and feels like an ‘out’ parameter. You can test this out like so (this may be version dependent): function DoNothing: IInterface; begin if Assigned(Result) then ShowMessage(‘result assigned before invocation’) else ShowMessage(‘result NOT assigned before invocation’); end; … Read more

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

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