如果我使用 Synchronize(GetResult); 以下代码会导致我的应用程序崩溃 AniIndi 变得反应迟钝。我认为问题在于线程被破坏的方式。有人可以帮忙吗?
Type
TSearchRxT = class(TThread)
public
Token: string;
Token1, Token2, Token3: String;
SearchByPat: Boolean;
constructor Create(const Patient: boolean); reintroduce;
protected
procedure GetResult;
procedure Execute; override;
end;
constructor TSearchRxT.Create(const Patient: boolean);
begin
inherited Create(True);
end;
Function TCommonRoutines.SearchRx(Token: String):Boolean;
Var TThread;
Token1, Token2, Token3: String;
begin
FrmMain.AniIndi.Visible := True;
FrmMain.AniIndi.Enabled := True;
FrmMain.OpenOTC := False;
CommonRoutine.MultiToken(Token, Token1, Token2, Token3); //defragment
string
//================================
SearchRxT := TSearchRxT.Create(True);
SearchRxT.Token1 := Token1;
SearchRxT.Token2 := Token2;
SearchRxT.Token3 := Token3;
SearchRxT.Token := Token; //Host
SearchRxT.OnTerminate := SearchPatThreadTerminated;
SearchRxT.Start;
end;
procedure TSearchRxT.Execute;
Var
i: Extended;
begin
while not Terminated do
begin
TThread.Sleep(200);
//Synchronize(GetResult);
With ClientModuleSignature do
begin
//Query Database (select * from myTable);
end;
end;
end;
procedure TCommonRoutines.SearchPatThreadTerminated(Sender: TObject);
begin
SearchRxT := nil;
FrmMain.OpenOTC := True;
FrmMain.AniIndi.Enabled := False;
FrmMain.AniIndi.Visible := False;
FrmMain.lvPacientes.Repaint;
end;
我添加了线程定义。