@@ -4048,15 +4048,19 @@ procedure TPythonEngine.Finalize;
4048
4048
Finalize;
4049
4049
end ;
4050
4050
// Then finalize Python, if we have to
4051
- if Initialized and FAutoFinalize then
4051
+ if Initialized and FAutoFinalize then begin
4052
4052
try
4053
- FFinalizing := True;
4054
- Py_Finalize;
4055
- finally
4056
- FFinalizing := False;
4057
- FInitialized := False;
4053
+ try
4054
+ FFinalizing := True;
4055
+ Py_Finalize;
4056
+ finally
4057
+ FFinalizing := False;
4058
+ FInitialized := False;
4059
+ end ;
4060
+ except
4058
4061
end ;
4059
- // Detach our clients, when engine is beeing destroyed or one of its clients.
4062
+ end ;
4063
+ // Detach our clients, when engine is being destroyed or one of its clients.
4060
4064
canDetachClients := csDestroying in ComponentState;
4061
4065
if not canDetachClients then
4062
4066
for i := 0 to ClientCount - 1 do
@@ -4216,16 +4220,12 @@ procedure TPythonEngine.Initialize;
4216
4220
raise Exception.Create(' There is already one instance of TPythonEngine running' );
4217
4221
4218
4222
gPythonEngine := Self;
4219
- // CheckRegistry; //AT: disabled
4220
- if Assigned(Py_SetProgramName) then
4221
- begin
4222
- if FProgramName = ' ' then
4223
- FProgramName := UnicodeString(ParamStr(0 ));
4224
- Py_SetProgramName(PWideChar(FProgramName));
4225
- end ;
4223
+ CheckRegistry;
4224
+ if Assigned(Py_SetProgramName) and (Length(FProgramName) > 0 ) then
4225
+ Py_SetProgramName(PWCharT(FProgramName));
4226
4226
AssignPyFlags;
4227
- if FPythonHome <> ' ' then
4228
- Py_SetPythonHome(PWideChar (FPythonHome));
4227
+ if Length( FPythonHome) > 0 then
4228
+ Py_SetPythonHome(PWCharT (FPythonHome));
4229
4229
Py_Initialize;
4230
4230
if Assigned(Py_IsInitialized) then
4231
4231
FInitialized := Py_IsInitialized() <> 0
@@ -5094,8 +5094,8 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject;
5094
5094
varShortInt,
5095
5095
varWord,
5096
5096
varLongWord,
5097
- varInteger: Result := PyLong_FromLong( integer (DeRefV) );
5098
- varInt64: Result := PyLong_FromLongLong( Int64( DeRefV) );
5097
+ varInteger: Result := PyLong_FromLong( LongInt (DeRefV) );
5098
+ varInt64: Result := PyLong_FromLongLong( DeRefV );
5099
5099
varSingle,
5100
5100
varDouble,
5101
5101
varCurrency: Result := PyFloat_FromDouble( DeRefV );
@@ -5108,7 +5108,7 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject;
5108
5108
begin
5109
5109
wd := (DayOfWeek( dt ) + 7 - 2 ) mod 7 ; // In Python, Monday is the first day (=0)
5110
5110
jd := Round(EncodeDate(y,m,d)-EncodeDate(y,1 ,1 ))+1 ; // This shoud be the Julian day, the day in a year (0-366)
5111
- dl := -1 ; // This is daylight save... ?????? ? I don't know what it is...
5111
+ dl := -1 ; // This is daylight save... ?Ξ?Ξ ? I don't know what it is...
5112
5112
Result := ArrayToPyTuple( [y, m, d, h, mi, sec, wd, jd, dl] );
5113
5113
end
5114
5114
else if (DatetimeConversionMode = dcmToDatetime) then
@@ -5132,7 +5132,7 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject;
5132
5132
wStr := ' '
5133
5133
else
5134
5134
wStr := DeRefV;
5135
- Result := PyUnicode_FromWideChar( PWideChar( wStr), Length(wStr) );
5135
+ Result := PyUnicodeFromString( wStr);
5136
5136
end ;
5137
5137
varString:
5138
5138
begin
@@ -5141,8 +5141,8 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject;
5141
5141
end ;
5142
5142
varUString:
5143
5143
begin
5144
- wStr := DeRefV;
5145
- Result := PyUnicode_FromWideChar( PWideChar( wStr), Length(wStr) );
5144
+ wStr := DeRefV;
5145
+ Result := PyUnicodeFromString( wStr);
5146
5146
end ;
5147
5147
else
5148
5148
if VarType(DeRefV) and varArray <> 0 then
0 commit comments