Jetzt noch ClassType statt Class und dann geht's!
Delphi-Quellcode:
type
TAnimal =
class
public
Name:
String;
end;
TDog =
class(TAnimal)
public
Hairs: Integer;
end;
TCat =
class(TAnimal)
public
Color: Integer;
end;
TAnimalClass =
class of TAnimal;
var
Animal1, Animal2: TAnimal;
begin
try
Animal1 := TDog.Create;
Animal2 := TAnimalClass(Animal1.ClassType).Create;
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
end.