@@ -4218,7 +4218,7 @@ procedure TPythonEngine.Initialize;
4218
4218
CheckRegistry;
4219
4219
if Assigned(Py_SetProgramName) then
4220
4220
begin
4221
- if FProgramName = ' ' then
4221
+ if ProgramName = ' ' then
4222
4222
ProgramName := UnicodeString(ParamStr(0 ));
4223
4223
Py_SetProgramName(PWCharT(FProgramName));
4224
4224
end ;
@@ -4375,23 +4375,33 @@ procedure TPythonEngine.CheckRegistry;
4375
4375
4376
4376
procedure TPythonEngine.SetProgramArgs ;
4377
4377
var
4378
- i , argc : Integer;
4378
+ I , argc : Integer;
4379
4379
wargv : array of PWCharT;
4380
4380
WL : array of WCharTString;
4381
+ TempS: UnicodeString;
4381
4382
begin
4382
4383
// 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.
4384
4385
argc := ParamCount;
4385
4386
SetLength(wargv, argc + 1 );
4386
4387
// build the PWideChar array
4387
4388
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);
4389
4399
{ $IFDEF POSIX}
4390
- WL := UnicodeStringToUCS4String(ParamStr(i) );
4400
+ WL := UnicodeStringToUCS4String(TempS );
4391
4401
{ $ELSE}
4392
- WL[i ] := UnicodeString(ParamStr(i) );
4402
+ WL[I ] := UnicodeString(TempS );
4393
4403
{ $ENDIF}
4394
- wargv[i ] := PWCharT(WL[i ]);
4404
+ wargv[I ] := PWCharT(WL[I ]);
4395
4405
end ;
4396
4406
// set the argv list of the sys module with the application arguments
4397
4407
PySys_SetArgv( argc + 1 , PPWCharT(wargv) );
0 commit comments