1

I have problem with new released delphi 10.2 the new compiler show error when

var 
  FGlobalVar: array of integer;

procedure SomeProc()
var
  ALocalVar: array of integer;
begin 
  ALocalVar := Pointer(FGlobalVar); {assign dynamic array}
  {Do Something}
end;

In previous version compiler delphi not show any errors.

1 Answer 1

5

That code should never have compiled, and Tokyo closes the loop hole. The problem with that cast is that reference counting can by bypassed. The code as you have it does not suffer that problem, but if the cast is written on the left hand side of the assignment, then no reference is taken.

Pointer(LocalVar) := GlobalVar;

Written this way round, LocalVar is assigned a reference to the dynamic array but the reference count is not incremented. I appreciate that your code is not written this way round, but I believe that this is the reason why the developers chose to make the change.

In any case, yhere is no need for the cast if you use types that are compatible. Switch to TArray<Integer> and the cast is not necessary. Further, your code will be able to interact with generic methods.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.