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.

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to