I have classnames in a stringlist. For example it could be \'TPlanEvent\', \'TParcel\', \'TCountry\' etc.
Now I want to find out the sizes by looping the list.
In Delphi 2010 you can use:
function StringToClass(AName: string): TClass;
var
LCtx: TRttiContext;
LTp: TRttiType;
begin
Result := nil;
try
LTp := LCtx.FindType(AClassName);
except
Exit;
end;
if (LTp <> nil) and (LTp is TRttiInstanceType) then
Result := TRttiInstanceType(LTp).Metaclass;
end;
One note. Since you only keep the class names in the list this method will not work because TRttiContext.FindType expects a fully qualified type name (ex. uMyUnit.TMyClass). The fix is to attach the unit where you store these classes in the loop or in the list.