-3

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.

user734781
  • 273
  • 1
  • 9
  • 19
  • You need to add your variables' type declarations to your q, otherwise how do you expect readers to be able to answer? – MartynA Mar 20 '19 at 19:28
  • You did not show what `GetResult()` does. Is it where you call `SearchRxT.Terminate()`? – Remy Lebeau Mar 20 '19 at 21:11
  • The GetResult() is a process that queries the database, "select * from myTable"), if I add that code to the GetResult the AniIndi becomes irresponsive and the application does not crash. – user734781 Mar 21 '19 at 01:24
  • The essence of the question is how do I make a component such as TAnilIndicator responsive while populating a TListView while calling a procedure to query a database on an iOS environment. – user734781 Mar 21 '19 at 01:52

1 Answers1

0

I found the problem to this issue while executing the thread, I called DisableControls prior to iterating through a large number of records in the dataset to prevent data-aware controls from updating every time the active record changed, which was causing a memory error when trying to update a listView.

user734781
  • 273
  • 1
  • 9
  • 19