Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6cd46ca

Browse files
committed
Removed CheckRegistry and associated OnPathInitialization event. It was a bad way to change the python path by modifying the Windows Registry.
1 parent d26ede5 commit 6cd46ca

File tree

1 file changed

+0
-76
lines changed

1 file changed

+0
-76
lines changed

Source/PythonEngine.pas

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,6 @@ TPythonInterface=class(TDynamicDll)
19621962
DEFAULT_DATETIME_CONVERSION_MODE = dcmToTuple;
19631963
type
19641964
TEngineClient = class;
1965-
TPathInitializationEvent = procedure ( Sender : TObject; var Path : string ) of Object;
19661965
TSysPathInitEvent = procedure ( Sender : TObject; PathList : PPyObject ) of Object;
19671966
TPythonFlag = (pfDebug, pfInteractive, pfNoSite, pfOptimize, pfVerbose,
19681967
pfFrozenFlag, pfIgnoreEnvironmentFlag, pfIsolated);
@@ -2015,7 +2014,6 @@ TPythonEngine = class(TPythonInterface)
20152014
FPythonHome: UnicodeString;
20162015
FPythonPath: WCharTString;
20172016
FInitThreads: Boolean;
2018-
FOnPathInitialization: TPathInitializationEvent;
20192017
FOnSysPathInit: TSysPathInitEvent;
20202018
FTraceback: TPythonTraceback;
20212019
FUseWindowsConsole: Boolean;
@@ -2049,7 +2047,6 @@ TPythonEngine = class(TPythonInterface)
20492047
function GetClients( idx : Integer ) : TEngineClient;
20502048
procedure Notification(AComponent: TComponent;
20512049
Operation: TOperation); override;
2052-
procedure CheckRegistry;
20532050
procedure SetProgramArgs(var Config: PyConfig);
20542051
procedure InitWinConsole;
20552052
procedure SetUseWindowsConsole( const Value : Boolean );
@@ -2168,7 +2165,6 @@ TPythonEngine = class(TPythonInterface)
21682165
property RedirectIO: Boolean read FRedirectIO write FRedirectIO default True;
21692166
property UseWindowsConsole: Boolean read FUseWindowsConsole write FUseWindowsConsole default False;
21702167
property OnAfterInit: TNotifyEvent read FOnAfterInit write FOnAfterInit;
2171-
property OnPathInitialization: TPathInitializationEvent read FOnPathInitialization write FOnPathInitialization;
21722168
property OnSysPathInit: TSysPathInitEvent read FOnSysPathInit write FOnSysPathInit;
21732169
end;
21742170

@@ -4757,14 +4753,6 @@ procedure TPythonEngine.Initialize;
47574753
FInitialized := True
47584754
else
47594755
begin
4760-
// CheckRegistry;
4761-
// if Assigned(Py_SetProgramName) and (Length(FProgramName) > 0) then
4762-
// Py_SetProgramName(PWCharT(FProgramName));
4763-
// AssignPyFlags;
4764-
// if Length(FPythonHome) > 0 then
4765-
// Py_SetPythonHome(PWCharT(FPythonHome));
4766-
// Py_Initialize;
4767-
47684756
// Fills Config with zeros and then sets some default values
47694757
if pfIsolated in FPyFlags then
47704758
PyConfig_InitIsolatedConfig(Config)
@@ -4872,62 +4860,6 @@ procedure TPythonEngine.Notification( AComponent: TComponent;
48724860
IO := nil
48734861
end;
48744862

4875-
procedure TPythonEngine.CheckRegistry;
4876-
{$IFDEF MSWINDOWS}
4877-
var
4878-
key : string;
4879-
Path : string;
4880-
NewPath : string;
4881-
{$IFDEF CPUX86}
4882-
LMajorVersion : integer;
4883-
LMinorVersion : integer;
4884-
{$ENDIF}
4885-
VersionSuffix: string;
4886-
{$ENDIF}
4887-
begin
4888-
{$IFDEF MSWINDOWS}
4889-
if Assigned( FOnPathInitialization ) then
4890-
try
4891-
with TRegistry.Create(KEY_ALL_ACCESS and not KEY_NOTIFY) do
4892-
try
4893-
VersionSuffix := '';
4894-
{$IFDEF CPUX86}
4895-
PythonVersionFromRegVersion(RegVersion, LMajorVersion, LMinorVersion);
4896-
if (LMajorVersion > 3) or ((LMajorVersion = 3) and (LMinorVersion >= 5)) then
4897-
VersionSuffix := '-32';
4898-
{$ENDIF}
4899-
key := Format('\Software\Python\PythonCore\%s%s\PythonPath', [RegVersion, VersionSuffix]);
4900-
4901-
RootKey := HKEY_LOCAL_MACHINE;
4902-
if not KeyExists( key ) then
4903-
begin
4904-
// try a current user installation
4905-
RootKey := HKEY_CURRENT_USER;
4906-
if not KeyExists( key ) then Exit;
4907-
end;
4908-
// Key found
4909-
OpenKey( key, True );
4910-
try
4911-
Path := ReadString('');
4912-
NewPath := Path;
4913-
FOnPathInitialization( Self, NewPath );
4914-
if NewPath <> Path then
4915-
begin
4916-
WriteString( '', NewPath );
4917-
end;
4918-
finally
4919-
CloseKey;
4920-
end;
4921-
finally
4922-
Free;
4923-
end;
4924-
except
4925-
// under WinNT, with a user without admin rights, the access to the
4926-
// LocalMachine keys would raise an exception.
4927-
end;
4928-
{$ENDIF}
4929-
end;
4930-
49314863
procedure TPythonEngine.SetProgramArgs(var Config: PyConfig);
49324864
var
49334865
I: Integer;
@@ -5045,11 +4977,7 @@ function TPythonEngine.GetSequenceItem(sequence: PPyObject;
50454977

50464978
procedure TPythonEngine.SetPythonHome(const PythonHome: UnicodeString);
50474979
begin
5048-
{$IFDEF POSIX}
5049-
FPythonHome := UnicodeStringToUCS4String(PythonHome);
5050-
{$ELSE}
50514980
FPythonHome := PythonHome;
5052-
{$ENDIF}
50534981
end;
50544982

50554983
procedure TPythonEngine.SetPythonPath(const Value: UnicodeString);
@@ -5063,11 +4991,7 @@ procedure TPythonEngine.SetPythonPath(const Value: UnicodeString);
50634991

50644992
procedure TPythonEngine.SetProgramName(const ProgramName: UnicodeString);
50654993
begin
5066-
{$IFDEF POSIX}
5067-
FProgramName := UnicodeStringToUCS4String(ProgramName);
5068-
{$ELSE}
50694994
FProgramName := ProgramName;
5070-
{$ENDIF}
50714995
end;
50724996

50734997
function TPythonEngine.EvalPyFunction(pyfunc, pyargs:PPyObject): Variant;

0 commit comments

Comments
 (0)