ShellExecute(Handle, 'open', PChar(edit1.text), nil, nil, SW_SHOWNORMAL);这句代码 运行一个外部程序( edit1.text='c:\game\client1.exe');如果直接在edit1.text 写入 c:\game\client1.exe 运行就提示 c++ runtime error如果用opendialog 选择c:\game\client1.exe 将filename属性赋值给edit1.text
在运行ShellExecute(Handle, 'open', PChar(edit1.text), nil, nil, SW_SHOWNORMAL);
就没问题,有人遇到过类似情况吗? 很奇怪啊

解决方案 »

  1.   

    程序运行所在目录的问题,调用都是用当前程序所在的目录(GetCurrentDir)为默认初始目录的
    前一种没改变目录,所以是按delphi程序的初始目录决定的;后一种情况下已经由OpeanDialog改变了当前的目录到了该exe所在的目录下
    那个exe文件显然是使用了相对目录来进行一些操作,而没有通过判断exe所在目录再加上相对路径取得相应的文件,所以就出错了
      

  2.   

    ShellExecute(Handle, 'open', PChar(edit1.text), nil, 'c:\game\', SW_SHOWNORMAL); 
    加上路径试试。