Class of | metaclass



Class of | metaclass
Smart pascal source code
type TBase = class Field: string; constructor Create; virtual; end; constructor TBase.Create; begin Field := 'Hello'; end; type TChild = class(TBase) constructor Create; override; end; constructor TChild.Create; begin Field := 'World'; end; type TBaseClass = class of TBase; { TEST II } Type TBaseClass2 = Class Constructor Create;// Virtual; Begin WriteLn(ClassName); End; End; Type TDescendant = Class(TBaseClass2) End; Type TClassRef = Class Of TBaseClass2; { TEST III } type TMyControl = TObject; type TMyControlClass = class of TMyControl; type TMySubControl = class (TMyControl); { main.pas } var meta: TBaseClass; obj1: TBase; cr : TClassRef; Begin if Assigned(meta) then Writeln('Assigned bug'); meta := TBase; if not Assigned(meta) then Writeln('Not Assigned bug'); obj1 := meta.Create; meta := TChild; var obj2 = meta.Create; if meta = TBase then Writeln('Bug Equal TBase'); if meta <> TChild then Writeln('Bug Not Equal TChild'); Writeln(obj1.Field); Writeln(obj2.Field); meta := nil; if Assigned(meta) then Writeln('Clear Assigned bug'); { ### CONSOLE OUTPUTS ### Hello World } { TEST II } cr := TDescendant; cr.Create; { ### CONSOLE OUTPUTS ### TDescendant } { TEST III } WriteLn(TMyControl.ClassName); WriteLn(TMyControlClass.ClassName); WriteLn(TMySubControl.ClassName); { ### CONSOLE OUTPUTS ### TObject TObject TMySubControl }