Skip to content

Commit 94c3033

Browse files
committed
Added VarPyToStrings
1 parent 583fcb0 commit 94c3033

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Source/VarPyth.pas

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
interface
4141

4242
uses
43-
Variants, PythonEngine;
43+
Variants, PythonEngine, Classes;
4444

4545
type
4646
TSequenceType = (stTuple, stList);
@@ -135,10 +135,12 @@ TVarPyEnumerateHelper = record
135135

136136
function VarPyIterate(const AValue: Variant): TVarPyEnumerateHelper;
137137

138+
function VarPyToStrings(const AValue : Variant; const AStrings: TStrings): Integer;
139+
138140
implementation
139141

140142
uses
141-
VarUtils, SysUtils, TypInfo, Classes;
143+
VarUtils, SysUtils, TypInfo;
142144

143145
type
144146
TNamedParamDesc = record
@@ -289,6 +291,7 @@ TPythonData = class(TObject)
289291
SCantConvertValueToPythonObject = 'Can''t convert Value into a Python object';
290292
SCantCreateNewSequenceObject = 'Can''t create a new sequence object';
291293
SExpectedPythonVariant = 'Expected a Python variant';
294+
SExpectedPythonList = 'Expected a Python List: ';
292295

293296
{ Python variant creation utils }
294297

@@ -2816,6 +2819,17 @@ function TVarPyEnumerateHelper.GetEnumerator: TVarPyEnumerator;
28162819
Result := TVarPyEnumerator.Create(FIterable);
28172820
end;
28182821

2822+
function VarPyToStrings(const AValue : Variant; const AStrings: TStrings): Integer;
2823+
begin
2824+
Assert(Assigned(AStrings));
2825+
if VarIsPythonList(AValue) then
2826+
GetPythonEngine.PyListToStrings(
2827+
ExtractPythonObjectFrom(AValue), AStrings)
2828+
else
2829+
raise Exception.Create(SExpectedPythonList + _type(AValue));
2830+
Result := AStrings.Count;
2831+
end;
2832+
28192833
initialization
28202834
PythonVariantType := TPythonVariantType.Create;
28212835

0 commit comments

Comments
 (0)