虚心实腹老大给的好难阿,菜鸟看不懂
我的代码如下。还有运行过以后需要释放线程,不然没有办法第二次调用。
---------------------------------
主线程:
Procedure TForm1.IntegratClick(Sender: TObject);
Const
Prog = 'Pre.exe';
ProgEnd = 'The termination of Pre.';
Var
ExitCode : Dword;
FileName,Result : String;
Restr : TStrings;
begin
ExitCode := 0;
FileName := XmPath + XmName;
CommandProg := Prog;
CommandPara := FileName;
Dir := XmPath;
RunThread := TRunThread.Create(True);
RunThread.FreeOnTerminate := True;
RunThread.Resume;
end;
-------------------------------
调用线程:
procedure TRunThread.Execute;
begin
If (Terminated) then
begin
showmessage('Program has exited.');
exit;
end;
RunDos();
end;
procedure TRunThread.RunDOS();
var
Cmdprog,Cmdpara,Dr:string;
execpara: String;
begin
CmdProg := Form1.CommandProg;
CmdPara := Form1.CommandPara;
dr := Form1.Dir;
execpara := 'E:/xm/pre.exe ' + CmdPara;
while not terminateddo
begin
IF ((CmdProg<>'')and(CmdPara<>'')) then
begin
winexec(Pchar(execpara), SW_HIDE );
// shellexecute(form1.handle,'open','E:/xm/pre.exe',PChar(CmdPara),nil,SW_HIDE);
//用createProcess也会出错的
end
else
begin
IF (CmdProg = '') then
ShowMessage('Nothing in Prog');
IF (CmdPara = '') then
ShowMessage('Nothing in Para');
Exit;
end;
end;
end;