EAccessViolation in function CreateProcess in Delphi 2009

很有趣的,我也遇到了這件事情,明明 CreateProcess 這函式在Delphi 7時就正常,到了Delphi 2009就出怪手了。


The problem is in the lpCommandLine parameter. I suspect you are doing something like this:
  CmdLine: string;
CmdLine := 'notepad.exe';
CreateProcess(nil, PChar(CmdLine), ...)

This results in an access violation because CmdLine is not writeable memory. The string is a constant string stored in read-only memory.

Instead you can do this:
CmdLine := 'notepad.exe';
CreateProcess(nil, PChar(CmdLine), ...)

This is enough to make CmdLine be backed by writeable memory.

It is not enough just to make the variable holding the string non-const, you need to make the memory that backs the string writeable too. When you assign a string literal to a string variable, the string variable points at read-only memory.

參考來源:Access Violation in function CreateProcess in Delphi 2009



JSON Parse in Delphi XE (03)

前情提要: JSON Parse in Delphi XE (01) JSON Parse in Delphi XE (02) 這篇要說明 JSON 格式在 Delphi 裡是怎麼被理解的。 JSON 名詞解釋: JSON(JavaScript Object N...