[fpc-devel] "class of TFoo".Create
J. Gareth Moreton
gareth at moreton-family.com
Sun Jul 6 16:31:05 CEST 2025
What I mean is that if you want to instantiate an object of class TFoo,
you'd call TFoo.Create, not TFooClass.Create.
If you want to take advantage of Object Pascal's unique polymorphism and
instantiate a descendant class of TFoo, you'd call
MetaClassVariable.Create rather than TFooClass.Create, where
MetaClassVariable is defined somewhere as "var MetaClassVariable:
TFooClass;" and then set it accordingly before the instantiation.
To just call TFooClass.Create, and TFooClass is implicitly converted to
TFoo, feels a bit 'off' and is asking for trouble, while seeing
"TFooClass.Create" in the code would be indictive of a bug in my
opinion, since the programmer either meant "TFoo" or a variable of type
TFooClass instead of "TFooClass" itself.
On 06/07/2025 15:17, Zoë Peterson via fpc-devel wrote:
>> I would personally call that unusual at best
>
> What do you two expect this construct to do that you think the current behavior is wrong? It’sobviously correct and expected to me as a fundamental part of Object Pascal’s polymorphism. Constructing an object from a class reference is the entire reason that constructors are virtual. It’s how things like TPicture.Graphic are implemented to create the correct image loading object.
>
> Zoë Peterson
> Scooter Software
>
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
--
This email has been checked for viruses by Avast antivirus software.
www.avast.com
More information about the fpc-devel
mailing list