unit u_MyThread; interface uses Classes; type TMyThread = class(TThread) private FOptype: string; FMailQueNo: string; FFlag: Boolean; procedure SetOptype(const Value: string); procedure SetMailQueNo(const Value: string); function Myfun(qno:string):Boolean; // 原本参数传递交由 TMyThread的实例赋值完成 protected procedure Execute; override; public property Optype: string read FOptype write SetOptype; property MailQueNo: string read FMailQueNo write SetMailQueNo; property MyFunRetVal: Boolean read FFlag default False; constructor Create(qno:string ); end; implementation uses u_tree_main; function TMyThread.Myfun; begin // 假设这里做了操作UI的工作 frm_tree_main.sendmailBatch(MailQueNo); FFlag := True; end; constructor TMyThread.Create(qno:string ); begin inherited Create(True); Self.FreeOnTerminate := True; MailQueNo:=qno; end; procedure TMyThread.Execute; begin // 让操作UI的代码放回主线程中执行已保证同步 //Synchronize(Myfun); FFlag := Myfun(FMailQueNo); end; procedure TMyThread.SetMailQueNo(const Value: string); begin FMailQueNo := Value; end; procedure TMyThread.SetOptype(const Value: string); begin FOptype := Value; end; end.