@@ -1170,6 +1170,7 @@ TDynamicDll = class(TComponent)
1170
1170
FOnBeforeLoad : TNotifyEvent;
1171
1171
FOnAfterLoad : TNotifyEvent;
1172
1172
FOnBeforeUnload : TNotifyEvent;
1173
+ FInExtensionModule : Boolean;
1173
1174
1174
1175
function Import (const funcname: AnsiString; canFail : Boolean = True): Pointer;
1175
1176
procedure Loaded ; override;
@@ -1189,6 +1190,7 @@ TDynamicDll = class(TComponent)
1189
1190
procedure OpenDll (const aDllName : string);
1190
1191
function IsHandleValid : Boolean;
1191
1192
procedure LoadDll ;
1193
+ procedure LoadDllInExtensionModule ;
1192
1194
procedure UnloadDll ;
1193
1195
procedure Quit ;
1194
1196
@@ -2978,7 +2980,7 @@ function TDynamicDll.GetDllPath : string;
2978
2980
begin
2979
2981
Result := DllPath;
2980
2982
2981
- if DLLPath = ' ' then begin
2983
+ if ( DLLPath = ' ' ) and not FInExtensionModule then begin
2982
2984
{ $IFDEF MSWINDOWS}
2983
2985
IsPythonVersionRegistered(RegVersion, Result, AllUserInstall);
2984
2986
{ $ENDIF}
@@ -3086,6 +3088,12 @@ procedure TDynamicDll.LoadDll;
3086
3088
OpenDll( DllName );
3087
3089
end ;
3088
3090
3091
+ procedure TDynamicDll.LoadDllInExtensionModule ;
3092
+ begin
3093
+ FInExtensionModule := True;
3094
+ LoadDLL;
3095
+ end ;
3096
+
3089
3097
procedure TDynamicDll.UnloadDll ;
3090
3098
begin
3091
3099
if IsHandleValid then begin
@@ -4223,26 +4231,34 @@ procedure TPythonEngine.Initialize;
4223
4231
raise Exception.Create(' There is already one instance of TPythonEngine running' );
4224
4232
4225
4233
gPythonEngine := Self;
4226
- CheckRegistry;
4227
- if Assigned(Py_SetProgramName) and (Length(FProgramName) > 0 ) then
4228
- Py_SetProgramName(PWCharT(FProgramName));
4229
- AssignPyFlags;
4230
- if Length(FPythonHome) > 0 then
4231
- Py_SetPythonHome(PWCharT(FPythonHome));
4232
- Py_Initialize;
4233
- if Assigned(Py_IsInitialized) then
4234
- FInitialized := Py_IsInitialized() <> 0
4235
- else
4236
- FInitialized := True;
4234
+
4237
4235
FIORedirected := False;
4238
- InitSysPath;
4239
- SetProgramArgs;
4236
+ if FInExtensionModule then
4237
+ FInitialized := True
4238
+ else
4239
+ begin
4240
+ CheckRegistry;
4241
+ if Assigned(Py_SetProgramName) and (Length(FProgramName) > 0 ) then
4242
+ Py_SetProgramName(PWCharT(FProgramName));
4243
+ AssignPyFlags;
4244
+ if Length(FPythonHome) > 0 then
4245
+ Py_SetPythonHome(PWCharT(FPythonHome));
4246
+ Py_Initialize;
4247
+ if Assigned(Py_IsInitialized) then
4248
+ FInitialized := Py_IsInitialized() <> 0
4249
+ else
4250
+ FInitialized := True;
4251
+ InitSysPath;
4252
+ SetProgramArgs;
4253
+ if InitThreads and Assigned(PyEval_InitThreads) then
4254
+ PyEval_InitThreads;
4255
+ if RedirectIO and Assigned(FIO) then
4256
+ DoRedirectIO;
4257
+ end ;
4258
+
4240
4259
GetTimeStructType;
4241
4260
GetDateTimeTypes;
4242
- if InitThreads and Assigned(PyEval_InitThreads) then
4243
- PyEval_InitThreads;
4244
- if RedirectIO and Assigned(FIO) then
4245
- DoRedirectIO;
4261
+
4246
4262
for i := 0 to ClientCount - 1 do
4247
4263
with Clients[i] do
4248
4264
if not Initialized then
0 commit comments