Skip to content

Commit 46145cb

Browse files
author
pyscripter
committed
Added VarPythonAsString
1 parent 7b5693c commit 46145cb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

PythonForDelphi/Components/Sources/Core/VarPyth.pas

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,14 @@ function NewPythonList( const ASize : Integer = 0 ): Variant;
9797
function NewPythonTuple( const ASize : Integer ): Variant;
9898
function NewPythonDict: Variant;
9999

100+
// Not really needed since you can assign a PythonVariant to a string anyway
101+
// but it is slightly faster and in some places avoids the declaration of a variable
102+
function VarPythonAsString(AValue : Variant) : string;
103+
100104
function None : Variant;
101105
function Ellipsis : Variant;
102106
function MainModule : Variant; // return the main module that's used for executing a script.
103-
function BuiltinModule : Variant; // return the builtin module
107+
function BuiltinModule : Variant; // return the builtin module
104108
function SysModule : Variant; // return the builtin module 'sys'
105109
function DatetimeModule : Variant; // return the builtin module 'datetime'
106110
function Import( const AModule : AnsiString ) : Variant; // import a Python module and return the module object.
@@ -636,6 +640,15 @@ function NewPythonDict: Variant;
636640
end; // of with
637641
end;
638642

643+
function VarPythonAsString(AValue : Variant) : string;
644+
begin
645+
if VarIsPython(AValue) then
646+
Result := TPythonVarData(AValue).VPython.AsString
647+
else
648+
Result := AValue;
649+
end;
650+
651+
639652
function None : Variant;
640653
begin
641654
with GetPythonEngine do

0 commit comments

Comments
 (0)