[fpc-devel] "class of TFoo".Create
    Martin Frb 
    lazarus at mfriebe.de
       
    Sun Jul  6 13:51:21 CEST 2025
    
    
  
I stumbled (by accident) on (maybe) a curiosity
TFooClass = class of TFoo;
can store a class (that must be TFoo or subclass of it).
I would have expected that the type TFooClass itself is not a class. 
(Its a container for a class / for lack of better wording)
Yet
TFooClass.Create
compiles. And creates an instance of type TFoo.
Is that intentional.
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.
    
    
More information about the fpc-devel
mailing list