@@ -4048,15 +4048,19 @@ procedure TPythonEngine.Finalize;
40484048 Finalize;
40494049 end ;
40504050 // Then finalize Python, if we have to
4051- if Initialized and FAutoFinalize then
4051+ if Initialized and FAutoFinalize then begin
40524052 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
40584061 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.
40604064 canDetachClients := csDestroying in ComponentState;
40614065 if not canDetachClients then
40624066 for i := 0 to ClientCount - 1 do
@@ -4216,16 +4220,12 @@ procedure TPythonEngine.Initialize;
42164220 raise Exception.Create(' There is already one instance of TPythonEngine running' );
42174221
42184222 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));
42264226 AssignPyFlags;
4227- if FPythonHome <> ' ' then
4228- Py_SetPythonHome(PWideChar (FPythonHome));
4227+ if Length( FPythonHome) > 0 then
4228+ Py_SetPythonHome(PWCharT (FPythonHome));
42294229 Py_Initialize;
42304230 if Assigned(Py_IsInitialized) then
42314231 FInitialized := Py_IsInitialized() <> 0
@@ -5094,8 +5094,8 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject;
50945094 varShortInt,
50955095 varWord,
50965096 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 );
50995099 varSingle,
51005100 varDouble,
51015101 varCurrency: Result := PyFloat_FromDouble( DeRefV );
@@ -5108,7 +5108,7 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject;
51085108 begin
51095109 wd := (DayOfWeek( dt ) + 7 - 2 ) mod 7 ; // In Python, Monday is the first day (=0)
51105110 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...
51125112 Result := ArrayToPyTuple( [y, m, d, h, mi, sec, wd, jd, dl] );
51135113 end
51145114 else if (DatetimeConversionMode = dcmToDatetime) then
@@ -5132,7 +5132,7 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject;
51325132 wStr := ' '
51335133 else
51345134 wStr := DeRefV;
5135- Result := PyUnicode_FromWideChar( PWideChar( wStr), Length(wStr) );
5135+ Result := PyUnicodeFromString( wStr);
51365136 end ;
51375137 varString:
51385138 begin
@@ -5141,8 +5141,8 @@ function TPythonEngine.VariantAsPyObject( const V : Variant ) : PPyObject;
51415141 end ;
51425142 varUString:
51435143 begin
5144- wStr := DeRefV;
5145- Result := PyUnicode_FromWideChar( PWideChar( wStr), Length(wStr) );
5144+ wStr := DeRefV;
5145+ Result := PyUnicodeFromString( wStr);
51465146 end ;
51475147 else
51485148 if VarType(DeRefV) and varArray <> 0 then
0 commit comments