Subject Re: [IBO] TIBODatabase and multithreading
Author piotr_3m
>
> 1. Do not mix components for the main thread and the ad hoc threads
> on the same datamodule.
>

I have followed all the rules you gave me and my app works very
stable. Now however I need to make my user interface more responsive.
I decided to do some kind of background queries. The easiest way is to
follow Delphi example {Delphi}\Demos\Db\BkQuery\. However example is
on BDE components and I don’t know if its safe to do the same with
IBOQuery. It seems to be against your first rule….

Can I with use IBOQuery created in separate thread to provide data for
VCL components (TDatasource in VCL Thread)?


- - - - - - - -

Bkquery example:
procedure TQueryThread.Execute;
var
UniqueNumber: Integer;
begin
try
with QueryForm do
begin
{ Ensure the Query has a unique session and database. A unique
session is required for each thread. Since databases are session
specific it must be unique as well }

{ Open the query }
Query.Open;

{ Connect the query to the grid. This must be done in a
synchronzied method since assigning the query to the DataSource will
modify the contents of the grid and the grid can only be modified from
the main VCL thread }
Synchronize(ConnectQuery);

end;
except
on E: Exception do
begin
end;
end;
end;

procedure TQueryThread.ConnectQuery;
begin
with QueryForm do DataSource.Dataset := Query;
end;

- - - - - - - -

Thanks for an ideas and examples,
Piotr