[fpc-devel] "class of TFoo".Create
J. Gareth Moreton
gareth at moreton-family.com
Sun Jul 6 15:11:58 CEST 2025
I would personally call that unusual at best. Logically I would
consider it a type mismatch or a syntax error of some kind, since TFoo
is a class and TFooClass is a metaclass. Also, if I saw such code in a
project, I would think someone made a mistake that didn't get caught,
since TFoo.Create would make much more sense.
I'd wonder if, under OBJFPC mode, such a construct should raise a
compiler error because I honestly can't see a situation where it would
be correct and intentional over using the associated class in its place.
Kit
On 06/07/2025 13:38, Bart via fpc-devel wrote:
> On Sun, Jul 6, 2025 at 1:57 PM Martin Frb via fpc-devel
> <fpc-devel at lists.freepascal.org> wrote:
>
>
>> program Project1;
>> {$mode objfpc}
>> type TFoo = class end;
>> TFooClass = class of TFoo;
>> var f: TFoo;
>> fc: TFooClass;
>> begin
>> fc := TFoo;
>> f := fc.Create;
>> f := TFooClass.Create; // works
>> end.
> Delphi (7) happily compiles that as well.
> And f is of type TFoo there as well.
>
--
This email has been checked for viruses by Avast antivirus software.
www.avast.com
More information about the fpc-devel
mailing list