Fun bug of the day:
Fun bug of the day:
function ExecProcess(const CommandLine: string): THandle;
var
si: TStartupInfo;
pi: TProcessInformation;
res: boolean;
begin
... init si and pi ...
res := CreateProcess(nil, PChar(CmdLine), nil, nil, false, 0, nil, nil, si, pi);
if not res then
RaiseLastOSError;
result := pi.hProcess;
end;
Hint: this compiles just fine in a dedicated unit.
function ExecProcess(const CommandLine: string): THandle;
var
si: TStartupInfo;
pi: TProcessInformation;
res: boolean;
begin
... init si and pi ...
res := CreateProcess(nil, PChar(CmdLine), nil, nil, false, 0, nil, nil, si, pi);
if not res then
RaiseLastOSError;
result := pi.hProcess;
end;
Hint: this compiles just fine in a dedicated unit.
What is the actual error you get?
ReplyDeletePaul Foster It doesn't start the right application ;)
ReplyDeleteIs it something to do with the variable name, er, constant 'pi'?
ReplyDeleteNicholas Ring Nope, as mentioned it compiles just fine in a dedicated unit, which is a hint in itself. A clash with a Pi constant would (should!) generate a type error. That it compiled just fine is of course why it took me a bit extra to find the issue.
ReplyDeleteWell you are passing cmdline, rather than the commandline parameter :-)
ReplyDeletePaul Foster And we have a winner :) Now, in my 15 years of TP/Delphi programming, I've never used or knew about the global CmdLine variable, as I simply had no reason to find out abou it.
ReplyDeleteAnother reason why I miss C++ namespaces...
You've never used the CmdLine variable? Good grief, thats been there since the year dot
ReplyDeletePaul Foster Guess I'm weird :P ParamStr() has done everything I've needed. It should be said I was mostly into 3D graphics and such before.
ReplyDelete