Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 58a99f6

Browse files
committed
better "overload" handling while searching for method
1 parent 741c164 commit 58a99f6

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

‎Source/WrapDelphi.pas‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,22 +2806,25 @@ function TPyDelphiMethodObject.Call(ob1, ob2: PPyObject): PPyObject;
28062806
PyValue : PPyObject;
28072807
Param: TRttiParameter;
28082808
Params : TArray<TRttiParameter>;
2809+
SearchContinue: Boolean;
28092810
begin
2810-
Result :=nil;
2811+
Result :=nil;
28112812
for Method in RttiType.GetMethods do
28122813
if SameText(Method.Name, MethName) then
28132814
begin
2814-
Params:=Method.GetParameters;
2815-
if Length(Args)=Length(Params) then
2815+
Params := Method.GetParameters;
2816+
if Length(Args) = Length(Params) then
28162817
begin
28172818
Result := Method;
2818-
for Index:= 0 to Length(Params)-1 do
2819+
SearchContinue := False;
2820+
for Index := 0 to Length(Params) - 1 do
28192821
begin
28202822
Param := Params[Index];
28212823
if (Param.ParamType = nil) or
28222824
(Param.Flags * [TParamFlag.pfVar, TParamFlag.pfOut] <> []) then
28232825
begin
2824-
Result :=nil;
2826+
Result := nil;
2827+
SearchContinue := True;
28252828
Break;
28262829
end;
28272830

@@ -2860,8 +2863,10 @@ function TPyDelphiMethodObject.Call(ob1, ob2: PPyObject): PPyObject;
28602863
Result :=nil;
28612864
Break;
28622865
end;
2863-
end;
2864-
Break;
2866+
end; // for params
2867+
2868+
if not SearchContinue then
2869+
Break;
28652870
end;
28662871
end;
28672872
end;

‎Tests/WrapDelphiTest.pas‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ TTestRttiAccess = class
5454
function GetStaticArray: TStaticArray;
5555
property Fruit: TFruit read FFruit write FFruit;
5656
property Fruits: TFruits read FFruits write FFruits;
57-
57+
function SetStringField(var Value: Integer): string; overload;
58+
function SetStringField(const Value: string): string; overload;
5859
end;
5960

6061
TTestInterfaceImpl = class(TInterfacedObject, ITestInterface)
@@ -113,6 +114,8 @@ TTestWrapDelphi = class(TObject)
113114
procedure TestGetDynArray;
114115
[Test]
115116
procedure TestGetStaticArray;
117+
[Test]
118+
procedure TestMethodWithVarAndOverload;
116119
end;
117120

118121
implementation
@@ -396,6 +399,24 @@ procedure TTestWrapDelphi.TestDynArrayParameters;
396399
Assert.IsTrue(TestRttiAccess.Fruits = [Orange]);
397400
end;
398401

402+
procedure TTestWrapDelphi.TestMethodWithVarAndOverload;
403+
begin
404+
Rtti_Var.SetStringField('test');
405+
Assert.AreEqual('test', TestRttiAccess.StringField);
406+
end;
407+
408+
function TTestRttiAccess.SetStringField(const Value: string): string;
409+
begin
410+
StringField := Value;
411+
Result := StringField;
412+
end;
413+
414+
function TTestRttiAccess.SetStringField(var Value: Integer): string;
415+
begin
416+
StringField := IntToStr(Value);
417+
Result := StringField;
418+
end;
419+
399420
function TTestRttiAccess.GetDynArray: TInt64DynArray;
400421
var
401422
I: Integer;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /