* differentiate between a list of all parameters and one of only visible ones; the former is going to be used for Invoke while the latter is returned by GetParameters

git-svn-id: trunk@39887 -
This commit is contained in:
svenbarth 2018-10-07 12:25:39 +00:00
parent 0f7f9c2bb8
commit b8ae04140c

View File

@ -319,6 +319,7 @@ type
function GetMethodKind: TMethodKind; virtual; abstract; function GetMethodKind: TMethodKind; virtual; abstract;
function GetReturnType: TRttiType; virtual; abstract; function GetReturnType: TRttiType; virtual; abstract;
function GetVirtualIndex: SmallInt; virtual; abstract; function GetVirtualIndex: SmallInt; virtual; abstract;
function GetParameters(aWithHidden: Boolean): specialize TArray<TRttiParameter>; virtual; abstract;
public public
property CallingConvention: TCallConv read GetCallingConvention; property CallingConvention: TCallConv read GetCallingConvention;
property CodeAddress: CodePointer read GetCodeAddress; property CodeAddress: CodePointer read GetCodeAddress;
@ -332,7 +333,7 @@ type
property ReturnType: TRttiType read GetReturnType; property ReturnType: TRttiType read GetReturnType;
property VirtualIndex: SmallInt read GetVirtualIndex; property VirtualIndex: SmallInt read GetVirtualIndex;
function ToString: String; override; function ToString: String; override;
function GetParameters: specialize TArray<TRttiParameter>; virtual; abstract; function GetParameters: specialize TArray<TRttiParameter>; inline;
end; end;
TRttiStructuredType = class(TRttiType) TRttiStructuredType = class(TRttiType)
@ -558,7 +559,7 @@ type
private private
FIntfMethodEntry: PIntfMethodEntry; FIntfMethodEntry: PIntfMethodEntry;
FIndex: SmallInt; FIndex: SmallInt;
FParams: specialize TArray<TRttiParameter>; FParams, FParamsAll: specialize TArray<TRttiParameter>;
protected protected
function GetHandle: Pointer; override; function GetHandle: Pointer; override;
function GetName: String; override; function GetName: String; override;
@ -573,9 +574,9 @@ type
function GetMethodKind: TMethodKind; override; function GetMethodKind: TMethodKind; override;
function GetReturnType: TRttiType; override; function GetReturnType: TRttiType; override;
function GetVirtualIndex: SmallInt; override; function GetVirtualIndex: SmallInt; override;
function GetParameters(aWithHidden: Boolean): specialize TArray<TRttiParameter>; override;
public public
constructor Create(AParent: TRttiType; AIntfMethodEntry: PIntfMethodEntry; AIndex: SmallInt); constructor Create(AParent: TRttiType; AIntfMethodEntry: PIntfMethodEntry; AIndex: SmallInt);
function GetParameters: specialize TArray<TRttiParameter>; override;
end; end;
resourcestring resourcestring
@ -1295,20 +1296,23 @@ begin
FIndex := AIndex; FIndex := AIndex;
end; end;
function TRttiIntfMethod.GetParameters: specialize TArray<TRttiParameter>; function TRttiIntfMethod.GetParameters(aWithHidden: Boolean): specialize TArray<TRttiParameter>;
var var
param: PVmtMethodParam; param: PVmtMethodParam;
total, visible: SizeInt; total, visible: SizeInt;
context: TRttiContext; context: TRttiContext;
obj: TRttiObject; obj: TRttiObject;
begin begin
if Length(FParams) > 0 then if aWithHidden and (Length(FParamsAll) > 0) then
Exit(FParamsAll);
if not aWithHidden and (Length(FParams) > 0) then
Exit(FParams); Exit(FParams);
if FIntfMethodEntry^.ParamCount = 0 then if FIntfMethodEntry^.ParamCount = 0 then
Exit(Nil); Exit(Nil);
SetLength(FParams, FIntfMethodEntry^.ParamCount); SetLength(FParams, FIntfMethodEntry^.ParamCount);
SetLength(FParamsAll, FIntfMethodEntry^.ParamCount);
context := TRttiContext.Create; context := TRttiContext.Create;
try try
@ -1316,14 +1320,16 @@ begin
visible := 0; visible := 0;
param := FIntfMethodEntry^.Param[0]; param := FIntfMethodEntry^.Param[0];
while total < FIntfMethodEntry^.ParamCount do begin while total < FIntfMethodEntry^.ParamCount do begin
obj := context.GetByHandle(param);
if Assigned(obj) then
FParamsAll[total] := obj as TRttiVmtMethodParameter
else begin
FParamsAll[total] := TRttiVmtMethodParameter.Create(param);
context.AddObject(FParamsAll[total]);
end;
if not (pfHidden in param^.Flags) then begin if not (pfHidden in param^.Flags) then begin
obj := context.GetByHandle(param); FParams[visible] := FParamsAll[total];
if Assigned(obj) then
FParams[visible] := obj as TRttiVmtMethodParameter
else begin
FParams[visible] := TRttiVmtMethodParameter.Create(param);
context.AddObject(FParams[visible]);
end;
Inc(visible); Inc(visible);
end; end;
@ -1331,12 +1337,16 @@ begin
Inc(total); Inc(total);
end; end;
SetLength(FParams, visible); if visible <> total then
SetLength(FParams, visible);
finally finally
context.Free; context.Free;
end; end;
Result := FParams; if aWithHidden then
Result := FParamsAll
else
Result := FParams;
end; end;
{ TRttiFloatType } { TRttiFloatType }
@ -2220,6 +2230,11 @@ begin
Result := FString; Result := FString;
end; end;
function TRttiMethod.GetParameters: specialize TArray<TRttiParameter>;
begin
Result := GetParameters(False);
end;
{ TRttiStringType } { TRttiStringType }
function TRttiStringType.GetStringKind: TRttiStringKind; function TRttiStringType.GetStringKind: TRttiStringKind;