2008-10-17

【Delphi】利用 Thread 物件在背景開啟 ADO query

 
type
    TOpenQuery = Class(TThread)
        Public
            constructor Create(Q:TADOQuery; sSQL:String);
        Protected
            tQry: TADOQuery;
            tSQL: String;
        Procedure Execute; override;
    end;

...
...

// TOpenQuery
constructor TOpenQuery.Create(Q: TADOQuery; sSQL: String);
begin
    inherited Create(False);
    FreeOnTerminate := True;
    tQry := Q;
    tSQL := sSQL;
end;

procedure TOpenQuery.Execute;
begin
    inherited;
    Screen.Cursor := crAppStart;
    with tQry do
    Begin
        SQL.Text := tSQL;
        Open;
    End;
    Screen.Cursor := crDefault;
end;
 

沒有留言:

張貼留言