|
40 | 40 | interface |
41 | 41 |
|
42 | 42 | uses |
43 | | - Variants, PythonEngine; |
| 43 | + Variants, PythonEngine, Classes; |
44 | 44 |
|
45 | 45 | type |
46 | 46 | TSequenceType = (stTuple, stList); |
@@ -135,10 +135,12 @@ TVarPyEnumerateHelper = record |
135 | 135 |
|
136 | 136 | function VarPyIterate(const AValue: Variant): TVarPyEnumerateHelper; |
137 | 137 |
|
| 138 | +function VarPyToStrings(const AValue : Variant; const AStrings: TStrings): Integer; |
| 139 | + |
138 | 140 | implementation |
139 | 141 |
|
140 | 142 | uses |
141 | | - VarUtils, SysUtils, TypInfo, Classes; |
| 143 | + VarUtils, SysUtils, TypInfo; |
142 | 144 |
|
143 | 145 | type |
144 | 146 | TNamedParamDesc = record |
@@ -289,6 +291,7 @@ TPythonData = class(TObject) |
289 | 291 | SCantConvertValueToPythonObject = 'Can''t convert Value into a Python object'; |
290 | 292 | SCantCreateNewSequenceObject = 'Can''t create a new sequence object'; |
291 | 293 | SExpectedPythonVariant = 'Expected a Python variant'; |
| 294 | + SExpectedPythonList = 'Expected a Python List: '; |
292 | 295 |
|
293 | 296 | { Python variant creation utils } |
294 | 297 |
|
@@ -2816,6 +2819,17 @@ function TVarPyEnumerateHelper.GetEnumerator: TVarPyEnumerator; |
2816 | 2819 | Result := TVarPyEnumerator.Create(FIterable); |
2817 | 2820 | end; |
2818 | 2821 |
|
| 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 | + |
2819 | 2833 | initialization |
2820 | 2834 | PythonVariantType := TPythonVariantType.Create; |
2821 | 2835 |
|
|
0 commit comments