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.

Comments

  1. Paul Foster It doesn't start the right application ;)

    ReplyDelete
  2. Is it something to do with the variable name, er, constant 'pi'?

    ReplyDelete
  3. Nicholas 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.

    ReplyDelete
  4. Well you are passing cmdline, rather than the commandline parameter :-)

    ReplyDelete
  5. Paul 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.

    Another reason why I miss C++ namespaces...

    ReplyDelete
  6. You've never used the CmdLine variable? Good grief, thats been there since the year dot

    ReplyDelete
  7. Paul 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

Post a Comment