How to correctly keep TAniIndi and a ListView responsive with a thread while Querying a Database on iOS?

  

The following code is causing my Applicatrion to crash, if I use Synchronize(GetResult); the AniIndi becomes irresponsive. I think that the problem rallies on the way the Thread is being destroyed. Can anyone please help?

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;

I’ve added the Thread definition.

Comments are closed.