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 X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...