@@ -1517,7 +1517,6 @@ TPythonInterface=class(TDynamicDll)
15171517 FMajorVersion: integer;
15181518 FMinorVersion: integer;
15191519 FBuiltInModuleName: string;
1520- function GetInitialized : Boolean;
15211520
15221521 procedure AfterLoad ; override;
15231522 function GetQuitMessage : string; override;
@@ -2067,13 +2066,12 @@ TPythonInterface=class(TDynamicDll)
20672066 procedure MapDll ;
20682067
20692068 // Public properties
2070- property Initialized : Boolean read GetInitialized ;
2069+ property Initialized : Boolean read FInitialized ;
20712070 property Finalizing : Boolean read FFinalizing;
20722071 property IsPython3000 : Boolean read FIsPython3000;
20732072 property MajorVersion : integer read FMajorVersion;
20742073 property MinorVersion : integer read FMinorVersion;
20752074 property BuiltInModuleName: string read FBuiltInModuleName write FBuiltInModuleName;
2076-
20772075end ;
20782076
20792077// --------------------------------------------------------
@@ -3516,6 +3514,7 @@ constructor TPythonInterface.Create(AOwner: TComponent);
35163514 i : Integer;
35173515begin
35183516 inherited ;
3517+ FInitialized := False;
35193518 i := COMPILED_FOR_PYTHON_VERSION_INDEX;
35203519 DllName := PYTHON_KNOWN_VERSIONS[i].DllName;
35213520 FAPIVersion := PYTHON_KNOWN_VERSIONS[i].APIVersion;
@@ -3556,14 +3555,6 @@ function TPythonInterface.GetQuitMessage : string;
35563555 Result := Format( ' Python could not be properly initialized. We must quit.' , [DllName]);
35573556end ;
35583557
3559- function TPythonInterface.GetInitialized : Boolean;
3560- begin
3561- if Assigned(Py_IsInitialized) then
3562- Result := Py_IsInitialized() <> 0
3563- else
3564- Result := FInitialized;
3565- end ;
3566-
35673558procedure TPythonInterface.CheckPython ;
35683559begin
35693560 if not Initialized then
@@ -4589,7 +4580,6 @@ constructor TPythonEngine.Create(AOwner: TComponent);
45894580begin
45904581 inherited ;
45914582 FLock := TCriticalSection.Create;
4592- FInitialized := False;
45934583 FInitScript := TstringList.Create;
45944584 FClients := TList.Create;
45954585 FRedirectIO := True;
@@ -4660,6 +4650,7 @@ procedure TPythonEngine.Finalize;
46604650 Py_Finalize;
46614651 finally
46624652 FFinalizing := False;
4653+ FInitialized := False;
46634654 end ;
46644655 except
46654656 end ;
@@ -4873,7 +4864,10 @@ procedure TPythonEngine.Initialize;
48734864 Py_SetPythonHome(PAnsiChar(FPythonHome));
48744865 end ;
48754866 Py_Initialize;
4876- FInitialized := True;
4867+ if Assigned(Py_IsInitialized) then
4868+ FInitialized := Py_IsInitialized() <> 0
4869+ else
4870+ FInitialized := True;
48774871 FIORedirected := False;
48784872 InitSysPath;
48794873 SetProgramArgs;
0 commit comments