Thread内でTableの読み込みを行うには?


bote  2004-05-06 09:21:43  No: 8818

はじめまして。
あるTableのFieldをStringListに追加していき、StringListのFindを使用して、入力データのチェックに使用しています。
Tableのレコード数が数万件あり時間がかかるため、Threadを利用してユーザーには、読み込み中に他の操作を出来ようにしてあります。
type
  TForm1 = class(TForm)
    Keytable: TTable;
    Keyfield: TStringField;
    procedure FormPaint(Sender: TObject);
  private
  public
    FKeyList:TstringList;
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
type
  TGetKey=class(TThread) //キー項目を読み込むThread
  private
    FEof:Boolean;
    Procedure OpenTable;
    Procedure GetField;
    Procedure CloseTable;
  protected
    procedure Execute; override;
  public
    constructor Create;
end;
procedure  TGetKey.OpenTable;   //テーブルをオープン
begin
  Form1.Keytable.Active:=true;
  FEof:=Form1.Keytable.Eof
end;
Procedure TGetKey.GetField;    //キー項目をStringListに追加
begin
  with Form1 do
  begin
    FKeyList.add(Keyfield.asstring);
    Keytable.Next;
    FEof:=Keytable.Eof
  end
end;
Procedure TGetKey.CloseTable;  //テーブルをクローズ
begin
  Form1.Keytable.Active:=False
end;
constructor TGetKey.Create;
begin
  FreeOnTerminate := True;
  inherited Create(False)
end;
procedure TGetKey.Execute;
begin
  Synchronize(OpenTable);
  while not FEof do
    Synchronize(GetField);
  Synchronize(CloseTable)
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
  FKeyList:=TstringList.Create;
  TGetKey.Create;
  Onpaint:=nil
end;
しかし、Synchronizeメソッドは一旦threadを停止させるためが無駄なように思います。Executeメソッド内でTableの読み込みは可能でしょうか?識者のお知恵を貸してください。


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加