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 (02)

在 JSON Parse in Delphi XE (01) 裡提到因為文字轉碼失敗引發的錯誤 今天就來試著解決這個問題 首先的判斷是: Indy 的 BUG? 那就來看看其它的軟體是否能被正確顯示: