@@ -4218,7 +4218,7 @@ procedure TPythonEngine.Initialize;
42184218 CheckRegistry;
42194219 if Assigned(Py_SetProgramName) then
42204220 begin
4221- if FProgramName = ' ' then
4221+ if ProgramName = ' ' then
42224222 ProgramName := UnicodeString(ParamStr(0 ));
42234223 Py_SetProgramName(PWCharT(FProgramName));
42244224 end ;
@@ -4375,23 +4375,33 @@ procedure TPythonEngine.CheckRegistry;
43754375
43764376procedure TPythonEngine.SetProgramArgs ;
43774377var
4378- i , argc : Integer;
4378+ I , argc : Integer;
43794379 wargv : array of PWCharT;
43804380 WL : array of WCharTString;
4381+ TempS: UnicodeString;
43814382begin
43824383 // we build a string list of the arguments, because ParamStr returns a volatile string
4383- // and we want to build an array of PAnsiChar , pointing to valid strings.
4384+ // and we want to build an array of PWCharT , pointing to valid strings.
43844385 argc := ParamCount;
43854386 SetLength(wargv, argc + 1 );
43864387 // build the PWideChar array
43874388 SetLength(WL, argc+1 );
4388- for i := 0 to argc do begin
4389+ for I := 0 to argc do begin
4390+ {
4391+ ... the first entry should refer to the script file to be executed rather
4392+ than the executable hosting the Python interpreter. If there isn’t a
4393+ script that will be run, the first entry in argv can be an empty string.
4394+ }
4395+ if I = 0 then
4396+ TempS := ' '
4397+ else
4398+ TempS := ParamStr(I);
43894399 { $IFDEF POSIX}
4390- WL := UnicodeStringToUCS4String(ParamStr(i) );
4400+ WL := UnicodeStringToUCS4String(TempS );
43914401 { $ELSE}
4392- WL[i ] := UnicodeString(ParamStr(i) );
4402+ WL[I ] := UnicodeString(TempS );
43934403 { $ENDIF}
4394- wargv[i ] := PWCharT(WL[i ]);
4404+ wargv[I ] := PWCharT(WL[I ]);
43954405 end ;
43964406 // set the argv list of the sys module with the application arguments
43974407 PySys_SetArgv( argc + 1 , PPWCharT(wargv) );
0 commit comments