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 ae50a7e

Browse files
committed
rtti invoke - variant parameter with array inside
1 parent ad2fa43 commit ae50a7e

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

‎Source/WrapDelphi.pas‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,13 +1040,17 @@ function SimplePythonToValue(PyValue: PPyObject; TypeInfo: PTypeInfo;
10401040
Value := V.Cast(TypeInfo);
10411041
Result := True;
10421042
end;
1043-
tkInteger, tkFloat, tkInt64,
1044-
tkVariant:
1043+
tkInteger, tkFloat, tkInt64:
10451044
begin
10461045
V := TValue.FromVariant(GetPythonEngine.PyObjectAsVariant(PyValue));
10471046
Value := V.Cast(TypeInfo);
10481047
Result := True;
10491048
end;
1049+
tkVariant:
1050+
begin
1051+
Value := TValue.From<Variant>(GetPythonEngine.PyObjectAsVariant(PyValue));
1052+
Result := True;
1053+
end;
10501054
tkEnumeration:
10511055
begin
10521056
S := GetPythonEngine.PyObjectAsString(PyValue);

‎Tests/WrapDelphiTest.pas‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ TTestRttiAccess = class
5757
property Fruits: TFruits read FFruits write FFruits;
5858
function SetStringField(var Value: Integer): string; overload;
5959
function SetStringField(const Value: string): string; overload;
60+
procedure PassVariantArray(const Value: Variant);
6061
end;
6162

6263
TTestInterfaceImpl = class(TInterfacedObject, ITestInterface)
@@ -118,7 +119,9 @@ TTestWrapDelphi = class(TObject)
118119
[Test]
119120
procedure TestMethodWithVarAndOverload;
120121
[Test]
121-
procedure FreeReturnedObject;
122+
procedure TestFreeReturnedObject;
123+
[Test]
124+
procedure TestPassVariantArray;
122125
end;
123126

124127
implementation
@@ -142,7 +145,7 @@ procedure TTestRttiAccess.BuyFruits(AFruits: TFruits);
142145

143146
{ TTestVarPyth }
144147

145-
procedure TTestWrapDelphi.FreeReturnedObject;
148+
procedure TTestWrapDelphi.TestFreeReturnedObject;
146149
begin
147150
PythonEngine.ExecString(
148151
'from delphi import rtti_var' + sLineBreak +
@@ -333,6 +336,15 @@ procedure TTestWrapDelphi.TestObjectField;
333336
Assert.IsTrue(rtti_var.ObjectField = None);
334337
end;
335338

339+
procedure TTestWrapDelphi.TestPassVariantArray;
340+
begin
341+
PythonEngine.ExecString(
342+
'from delphi import rtti_var' + sLineBreak +
343+
'rtti_var.PassVariantArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])'
344+
);
345+
Assert.Pass;
346+
end;
347+
336348
procedure TTestWrapDelphi.TestRecord;
337349
begin
338350
Rtti_rec.StringField := 'abcd';
@@ -452,6 +464,11 @@ function TTestRttiAccess.GetStaticArray: TStaticArray;
452464
Result[I] := I;
453465
end;
454466

467+
procedure TTestRttiAccess.PassVariantArray(const Value: Variant);
468+
begin
469+
Assert.IsTrue(VarIsArray(Value) and (VarArrayHighBound(Value, 1) = 9));
470+
end;
471+
455472
procedure TTestRttiAccess.SellFruits(const AFruits: TFruitDynArray);
456473
var
457474
Fruit: TFruit;

0 commit comments

Comments
(0)

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