MyList.ClassName
Liefert nur den unqualifizierten Klassennamen, also was von mehreren gleichnamigen Typen soll denn nun genommen werden?
Delphi-Quellcode:
function GetConcreteGenericType(AClass: TClass): TRTTIType;
function ExtractQualifiedName(const AName: string): string;
var i: integer;
begin
i := Succ(Pos('<', AName));
Result := Copy(AName, i, Pos('>', AName) - i);
end;
var
lCTX: TRTTIContext;
begin
while Assigned(AClass) and (Pos('<', AClass.ClassName) = 0) do
AClass := AClass.ClassParent;
if Assigned(AClass) then
Result := lCTX.FindType(ExtractQualifiedName(AClass.ClassName))
else
Result := nil;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
TheType: TRTTIType;
begin
TheType := GetConcreteGenericType(TMyList);
if Assigned(TheType) then
//ShowMessage(TheType.AsInstance.MetaclassType.ClassName)
ShowMessage(TheType.ToString)
else
ShowMessage('nee, hier gibt''s nix zu sehn');
end;