如果要实时的话,可以在Application.Onidle 事件中添加代码,Delphi5已经有了
TApplicationEvents控件。
function 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;
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,
nil,
nil,
false,
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS,
nil,
nil,
StartupInfo,
ProcessInfo) then Result := -1
else begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
// GetExitCodeProcess(ProcessInfo.hProcess,Result);
end;
end;
procedure TForm1.ApplicationEvents1Idle(Sender: TObject;
var Done: Boolean);
begin
if FileExists('e:/XXX.dat') then
begin
WinExecAndWait32('WinZip.exe a xxx.zip xxx.dat',SW_SHOW);
DeleteFile('e:/xxx.dat');
end;
Done:=False;
end;