[fpc-pascal] parent class as a parameter type

Graeme Geldenhuys graemeg.lists at gmail.com
Sun Nov 13 17:56:46 CET 2011


On 12/11/2011, ik <idokan at ....> wrote:
>
> Since 2.6.0, when you write something like this:

I think it was even before this.

> procedure foo(AClass : TStrings);
> foo(MyStringList); // Will return an error that TStrings is expected ...
>
> I can not use TStringList as the parameter without casting it to TStrings.
> But I do not understand why this limitation added. Can you please explain
> it to me ?

I ran into the exact same issue this week, and also can't understand
why this is not allowed any more. It *is* allowed in Delphi (at least
D7). Luckily I could change my code to TStringList to work around the
problem.

So yes, if anybody could please explain what was the logic behind this
crippling change?

The other issue I have is passing a property value via a var or const
parameter. I used this a lot in my code too, and it worked for years
without problems. This again, is supported in Delphi too. I have no
idea why this was changed in FPC either. The work around looks damn
stupid too. Declare a local variable and assign the property to it,
then pass the local variable. In the end it has the same endresult,
but just inconveniences to the developer with these unnecessary local
variables.


-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://fpgui.sourceforge.net



More information about the fpc-pascal mailing list