我的程序中用到函数DeleteFile和WinExec两个函数。
用WinExec时,需要在Uses中添加 Uses WinProcs
但一添加它时编译到DeleteFile就出错。
不添加时WinExec 就编译不过去。
请问如何解决这个问题?

解决方案 »

  1.   

    WinExec in the Windows unit .
      

  2.   

    DeleteFile in the SysUtils unit .
      

  3.   

    给你个好用点的
    //执行程序并等待结束
    function TF_Export.WinExecAndWait32(FileName:String; Visibility :
    integer):Integer;
    var
      zAppName:array[0..512] of char;
      zCurDir:array[0..255] of char;
      WorkDir:String;
      StartupInfo:TStartupInfo;
      ProcessInfo:TProcessInformation;
      Res: Cardinal;
    begin
      StrPCopy(zAppName,FileName);
      GetDir(0,WorkDir);
      StrPCopy(zCurDir,WorkDir);
      FillChar(StartupInfo,Sizeof(StartupInfo),#0);
      StartupInfo.cb := Sizeof(StartupInfo);  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
      StartupInfo.wShowWindow := Visibility;
      if not CreateProcess(nil,
        zAppName,                      { pointer to command line string }
        nil,                           { pointer to process security attributes }
        nil,                           { pointer to thread security attributes }
        false,                         { handle inheritance flag }
        CREATE_NEW_CONSOLE or          { creation flags }
        NORMAL_PRIORITY_CLASS,
        nil,                           { pointer to new environment block }
        nil,                           { pointer to current directory name }
        StartupInfo,                   { pointer to STARTUPINFO }
        ProcessInfo) then Result := -1 { pointer to PROCESS_INF }
      else begin
        WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
        GetExitCodeProcess(ProcessInfo.hProcess,Res);
        Result := Res;
      end;
    end;
    //调用
     if WinExecAndWait32(Str1,SW_Show) = -1 then
        showmessage('失败');
      

  4.   

    你加一个SysUtils 单元试试。
      

  5.   

    用楼上的函数吧,可以等待你调用的EXE进程结束
      

  6.   

    WinExec不用 Uses WinProcs 吧?
    而且我按你说的方法编译都没问题。
    最好不用 WinProcs 单元。在检查DeleteFile函数参数有无错误。
      

  7.   

    将 WinProcs 和 Windows 单元放在 SysUtils 前面
    或者 用 SysUtils.DeleteFile()其实,用了 Windows 单元,可不再用 WinProcs 单元。