* FindType implementation from Henrique Werlang (bug ID 38252)

This commit is contained in:
michael 2021-01-23 10:37:01 +00:00
parent 761b632d8f
commit 0642e13f57
2 changed files with 34 additions and 0 deletions

View File

@ -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;

View File

@ -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;