Delphi Compiler Error
H2244 Pointer expression needs no Initialize/Finalize – need ^ operator?
Reason for the Error & Solution
You have attempted to finalize a Pointer type.
program Produce; var str : String; pstr : PString; begin str := 'Sharene'; pstr := @str; Finalize(pstr); (*note: do not attempt to use 'str' after this*) end.
In this example the pointer, pstr, is passed to the Finalize procedure. This causes an hint since pointers do not require finalization.
program Solve; var str : String; pstr : PString; begin str := 'Sharene'; pstr := @str; Finalize(pstr^); (*note: do not attempt to use 'str' after this*) end.
The solution to this problem is to apply the ^ operator to the pointer which is passed to the Finalization procedure.