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

Alexandre Leclerc alexandre.leclerc at gmail.com
Thu Jul 13 13:58:52 CEST 2006


2006/7/13, memsom <memsom at interalpha.co.uk>:
> 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..)

Thank you for the information. I did not know that.

> 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.

It made me revise my code and I'm able to do what you suggest. This is
a better approach that I usually take, but I took this code from an
example on VirtualTreeView and in order to test quickly I simply took
it like that. Now I'll remake the procedure into a function.

Best regards.

-- 
Alexandre Leclerc



More information about the fpc-pascal mailing list