Example of TMSQuery TDBGrid and thread
Example of TMSQuery TDBGrid and thread
May you post or describe an example on how to update a dataaware conponent (like a TDBGrid) using a TMSquery executed in a thread?
Basically a simple example in which i click a button, a query is run (for example select * from sysprocesses from sql server master db) and when the query returns the DBGrid is updated?
Thanks.
Basically a simple example in which i click a button, a query is run (for example select * from sysprocesses from sql server master db) and when the query returns the DBGrid is updated?
Thanks.
Is it safe to do the following?
Query is a TMSQuery placed on the form.
a DBGrid (I am using a cxGrid from DevExpress by the way) datasource a TMSquery are connected as usual.
constructor TQThread.Create(Query: TMSQuery);
begin
inherited Create(True);
FQuery := Query;
FreeOnTerminate := True;
Resume;
end;
procedure TQThread.Execute;
begin
FQuery.Open;
end;
procedure TForm5.btnThreadClick(Sender: TObject);
begin
TQThread.Create(Query1);
end;
Query is a TMSQuery placed on the form.
a DBGrid (I am using a cxGrid from DevExpress by the way) datasource a TMSquery are connected as usual.
constructor TQThread.Create(Query: TMSQuery);
begin
inherited Create(True);
FQuery := Query;
FreeOnTerminate := True;
Resume;
end;
procedure TQThread.Execute;
begin
FQuery.Open;
end;
procedure TForm5.btnThreadClick(Sender: TObject);
begin
TQThread.Create(Query1);
end;
But with FetchAll=False I don't have all the records in the grid.
I tried as you suggest, this is from dfm, anyway as I open the TMSQuery I cannot do any other thing (while I can do it when I use threads explicitly as described above).
object MSConnection1: TMSConnection
Options.MultipleActiveResultSets = True
Options.Provider = prNativeClient
Options.NativeClientVerison = ncAuto // this is not published in the object inspector
end
object MSQuery1: TMSQuery
Connection = MSConnection1
Options.NonBlocking = True
end
I tried as you suggest, this is from dfm, anyway as I open the TMSQuery I cannot do any other thing (while I can do it when I use threads explicitly as described above).
object MSConnection1: TMSConnection
Options.MultipleActiveResultSets = True
Options.Provider = prNativeClient
Options.NativeClientVerison = ncAuto // this is not published in the object inspector
end
object MSQuery1: TMSQuery
Connection = MSConnection1
Options.NonBlocking = True
end