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

memsom memsom at interalpha.co.uk
Thu Jul 13 10:00:36 CEST 2006


>> What IS true is that you can change the properties of S, even if it is
>> passed by value or as const. But the pointer S cannot be changed.
>
> I desired to change the pointer; manifestly I have to pass it as var.

Be aware that if you do this, you will lose the ability to pass any class
that descends from the param type. Var params have to be the smae type
exactly. The Delphi compiler will halt on an error if the exact type isn't
used (though, thinking about it, the "Strict var params" switch might
loosen this in Delphi..)

Best advice: Don't use var params for initialization. Either return the
instance of the class - and raise an exception if there is an error, or
use 'out' params, as it makes your intention clearer.

M





More information about the fpc-pascal mailing list