Delphi Error – H2244 Pointer expression needs no Initialize/Finalize – need ^ operator?

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.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...