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 save class names in a list, this method will not work because TRttiContext.FindType expects a fully qualified type name (for example, uMyUnit.TMyClass). The fix is ββto attach the device where you store these classes in a loop or in a list.
source share