I tried the following:
procedure ThisAndThat(bitmap: TBitmap);
begin
if not Assigned(bitmap) then
bitmap := TBitmap.Create;
end;
function Test: boolean;
var
bitmap: TBitmap;
begin
bitmap := nil;
ThisAndThat(bitmap);
Result := Assigned(bitmap);
bitmap.Free;
end;In Delphi a class is always treated as a 'var' when passed in a function since a class is a pointer to actual data; logical but confusing when begining in Delphi. So in Delphi Test() would return true. I made a function like this in Lazarus and I see that it's not working. This behave as a local copy of the class! Now in FPC I changed the procedure for:
procedure ThisAndThat(var bitmap: TBitmap);and this is working.
The question: I guess this is an other delphi mode thing? Is there a page with all these Delphi mode / FPC differences? I'll check the wiki right after.
I prefer the behaviour of FPC because it is consistent, but is it really a copy a of class?!?. Since my background, I'll have to check all my functions that have classes in parameters to make sure this is working as expected.
Best regards.
