如何在iOS上查询数据库时正确保持TAniIndi和ListView响应线程?

问题描述 投票:-3回答:1

如果我使用Synchronize(GetResult),以下代码会导致我的Applicatrion崩溃; 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;

我添加了Thread定义。

ios multithreading delphi firemonkey midas-server
1个回答
0
投票

我在执行线程时发现了这个问题,我在迭代数据集中的大量记录之前调用了DisableControls,以防止每次活动记录更改时数据感知控件都会更新,这在尝试时会导致内存错误更新listView。

© www.soinside.com 2019 - 2024. All rights reserved.