[fpc-pascal] Another Delphi mode question :) -- classes as parameter

Alexandre Leclerc alexandre.leclerc at gmail.com
Wed Jul 12 16:55:10 CEST 2006

I tried the following:

procedure ThisAndThat(bitmap: TBitmap);
  if not Assigned(bitmap) then
    bitmap := TBitmap.Create;

function Test: boolean;
  bitmap: TBitmap;
  bitmap := nil;
  Result := Assigned(bitmap);

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.

Alexandre Leclerc

More information about the fpc-pascal mailing list