diff --git a/packages/rtl/rtti.pas b/packages/rtl/rtti.pas index ba0456a..af49aed 100644 --- a/packages/rtl/rtti.pas +++ b/packages/rtl/rtti.pas @@ -82,6 +82,7 @@ type class function Create: TRTTIContext; static; procedure Free; + function FindType(const AQualifiedName: String): TRttiType; function GetType(aTypeInfo: PTypeInfo): TRTTIType; overload; function GetType(aClass: TClass): TRTTIType; overload; end; @@ -387,6 +388,7 @@ implementation var GRttiContext: TRTTIContext; + pas: TJSObject; external name 'pas'; procedure CreateVirtualCorbaInterface(InterfaceTypeInfo: Pointer; const MethodImplementation: TVirtualInterfaceInvokeEvent; out IntfVar); assembler; @@ -1083,6 +1085,32 @@ begin Result:=GetType(TypeInfo(aClass)); end; +function TRTTIContext.FindType(const AQualifiedName: String): TRttiType; +var + ModuleName, TypeName: String; + + Module: TTypeInfoModule; + + TypeFound: PTypeInfo; + +begin + Result := nil; + + for ModuleName in TJSObject.Keys(pas) do + if AQualifiedName.StartsWith(ModuleName + '.') then + begin + Module := TTypeInfoModule(pas[ModuleName]); + TypeName := Copy(AQualifiedName, Length(ModuleName) + 2, Length(AQualifiedName)); + + if Module.RTTI.HasOwnProperty(TypeName) then + begin + TypeFound := PTypeInfo(Module.RTTI[TypeName]); + + Exit(GetType(TypeFound)); + end; + end; +end; + { TRttiObject } function TRttiObject.GetAttributes: TCustomAttributeArray; diff --git a/packages/rtl/typinfo.pas b/packages/rtl/typinfo.pas index 3135d76..e8751cc 100644 --- a/packages/rtl/typinfo.pas +++ b/packages/rtl/typinfo.pas @@ -25,11 +25,17 @@ type TCallConv = (ccReg, ccCdecl, ccPascal, ccStdCall, ccSafeCall, ccCppdecl, ccFar16, ccOldFPCCall, ccInternProc, ccSysCall, ccSoftFloat, ccMWPascal); + + { TSectionRTTI } + TSectionRTTI = class external name 'rtl.tSectionRTTI'(TJSObject) + end; + { TTypeInfoModule } TTypeInfoModule = class external name 'pasmodule' public Name: String external name '$name'; + RTTI: TSectionRTTI external name '$rtti'; end; TTypeInfoAttributes = type TJSValueDynArray;