unit Unit2;
interface
type
TEnum = (enString, enInteger);
TClassType = class of TClass;
TClass = class // base class type
class function ReturnClassType(Enum : TEnum) : TClassType;
end;
TClass1 = class(TClass)
public
v : string;
TClass2 = class(TClass)
v : integer;
TTesterClass = class
procedure Test;
implementation
uses
Dialogs;
{ TClass }
class function TClass.ReturnClassType(Enum: TEnum): TClassType;
begin
case Enum of
enString : result:=TClass1;
enInteger : result:=TClass2;
{ TTesterClass }
procedure TTesterClass.Test;
var
ClassType : TClassType;
ValuedClass : TClass;
ClassType := TClass.ReturnClassType(enInteger);
ValuedClass := ClassType.Create;
ShowMessage(ValuedClass.ClassName); // <- returns "TClass2"
end.