@@ -1271,9 +1271,11 @@ procedure TPythonVariantType.DispInvoke(Dest: PVarData;
1271
1271
LNamedArgStart : Integer; // arg position of 1st named argument (if any)
1272
1272
I : integer;
1273
1273
begin
1274
+ SetLength(fNamedParams, CallDesc^.NamedArgCount);
1275
+ if CallDesc^.NamedArgCount = 0 then
1276
+ Exit;
1274
1277
LNamePtr := PAnsiChar(@CallDesc^.ArgTypes[CallDesc^.ArgCount]);
1275
1278
LNamedArgStart := CallDesc^.ArgCount - CallDesc^.NamedArgCount;
1276
- SetLength(fNamedParams, CallDesc^.NamedArgCount);
1277
1279
// Skip function Name
1278
1280
for I := 0 to CallDesc^.NamedArgCount - 1 do begin
1279
1281
LNamePtr := LNamePtr + Succ(Length(LNamePtr));
@@ -1285,25 +1287,25 @@ procedure TPythonVariantType.DispInvoke(Dest: PVarData;
1285
1287
Var
1286
1288
NewCallDesc : TCallDesc;
1287
1289
begin
1288
- if CallDesc^.NamedArgCount > 0 then GetNamedParams;
1289
- try
1290
- if (CallDesc^.CallType = CPropertyGet) and (CallDesc^.ArgCount = 1 ) then begin
1290
+ if CallDesc^.CallType = CDoMethod then
1291
+ GetNamedParams; // fNamedParams will be cleared in EvalPython
1292
+ if (CallDesc^.CallType = CPropertyGet) and (CallDesc^.ArgCount = 1 ) then
1293
+ begin
1291
1294
NewCallDesc := CallDesc^;
1292
1295
NewCallDesc.CallType := CDoMethod;
1293
- { $IFDEF PATCHEDSYSTEMDISPINVOKE}
1296
+ SetLength(fNamedParams, 0 );
1297
+ { $IFDEF PATCHEDSYSTEMDISPINVOKE}
1294
1298
PatchedDispInvoke(Dest, Source, @NewCallDesc, Params);
1295
- { $ELSE PATCHEDSYSTEMDISPINVOKE}
1299
+ { $ELSE PATCHEDSYSTEMDISPINVOKE}
1296
1300
inherited DispInvoke(Dest, Source, @NewCallDesc, Params);
1297
- { $ENDIF PATCHEDSYSTEMDISPINVOKE}
1298
- end else
1301
+ { $ENDIF PATCHEDSYSTEMDISPINVOKE}
1302
+ end
1303
+ else
1299
1304
{ $IFDEF PATCHEDSYSTEMDISPINVOKE}
1300
1305
PatchedDispInvoke(Dest, Source, CallDesc, Params);
1301
1306
{ $ELSE PATCHEDSYSTEMDISPINVOKE}
1302
1307
inherited ;
1303
1308
{ $ENDIF PATCHEDSYSTEMDISPINVOKE}
1304
- finally
1305
- if CallDesc^.NamedArgCount > 0 then SetLength(fNamedParams, 0 );
1306
- end ;
1307
1309
end ;
1308
1310
1309
1311
function TPythonVariantType.DoFunction (var Dest: TVarData;
@@ -1519,8 +1521,14 @@ function TPythonVariantType.EvalPython(const V: TVarData;
1519
1521
_Args : PPyObject;
1520
1522
_ArgLen : Integer;
1521
1523
_KW : PPyObject;
1524
+ LNamedParams : TNamedParamArray;
1522
1525
begin
1523
1526
Result := nil ;
1527
+
1528
+ // Store global fNamedParams and clear it ASAP
1529
+ LNamedParams := System.Copy(fNamedParams);
1530
+ SetLength(fNamedParams, 0 );
1531
+
1524
1532
with GetPythonEngine do
1525
1533
begin
1526
1534
// extract the associated Python object
@@ -1583,10 +1591,10 @@ function TPythonVariantType.EvalPython(const V: TVarData;
1583
1591
_ArgLen := 0
1584
1592
else
1585
1593
_ArgLen := Length(Arguments);
1586
- if Length(fNamedParams ) > 0 then
1594
+ if Length(LNamedParams ) > 0 then
1587
1595
begin
1588
1596
_KW := PyDict_New;
1589
- _ArgLen := fNamedParams [0 ].Index;
1597
+ _ArgLen := LNamedParams [0 ].Index;
1590
1598
end
1591
1599
else
1592
1600
_KW := nil ;
@@ -1595,8 +1603,8 @@ function TPythonVariantType.EvalPython(const V: TVarData;
1595
1603
try
1596
1604
for i := 0 to _ArgLen-1 do
1597
1605
PyTuple_SetItem( _Args, i, ArgAsPythonObject(i) );
1598
- for i := 0 to Length(fNamedParams )-1 do
1599
- PyDict_SetItemString(_KW, fNamedParams [i].Name , ArgAsPythonObject(fNamedParams [i].Index));
1606
+ for i := 0 to Length(LNamedParams )-1 do
1607
+ PyDict_SetItemString(_KW, LNamedParams [i].Name , ArgAsPythonObject(LNamedParams [i].Index));
1600
1608
1601
1609
// call the func or method, with or without named parameters (KW)
1602
1610
Result := PyEval_CallObjectWithKeywords(_obj, _Args, _KW);
0 commit comments