Re:Using one TTable Source between Multiple Forms
In article <DtDHB9....@world.std.com>, Darren J Forcier
<d...@world.std.com> writes
Quote
>Hi,
>I have a need to use one TTable source between multiple forms. I have
>a main customer entry tabbed-notebook dialog that I have set up with 4
>pages of customer information. Upon demand I want to give the user a
>browse window they can open up for quickly locating and searching a
>particular client. I am currently using a TBGrid object for the
>browser window.
>Right now I am using the same form with two different panel areas.
>This works ok for users with 1024 X 768 resolution, but unfortunately
>my target machine will have to be (ugh!) 640X480.
>This is an MDI application. I gleaned some tips out of one of the
>Borland Delphi sample apps, and tried to set up a TDatabase object on
>the main MDI parent window, and then configure a common alias name
>that both TTable objects in each child MDI window draw from. This
>seemed to work, but didn't manage to keep the windows in Synch as I
>was moving around inside the TBGrid based browser window.
>Does anyone have any examples of sharing a single TTable (or TQuery or
>TDataset) object between multiple windows for simultaneous window
>updating?
>Regards,
>Darren Forcier
You are almost there. Each TTable maintains its own cursor on the
Dataset, so they don't keep in sync with each other (though they do seem
update each other with any changes to the data). This behaviour is very
useful if you want to look at different records at the same time, or
index one dataset in twoo different ways.
The place to split is one higher up the chain: the TDatasource. You can
place one on each form, and connect all the data-aware controls on that
form to it. Then all you need is a TTable somewhere to which you connect
all the datasources. All the Datasources will share the same cursor, so
they'll all keep in sync.
The only problem is that TTables & TQuerys from other forms don't show
up in the list of Datasets for a TDatasource (whereas TDatabases from
other forms DO show up in the Database list for a TTable). This means
that you have to explicitly make the connection in code:
TForm2.Create(Sender : TObject);
begin
DataSource1.Dataset := Form1.Table1;
end;
This inconsistency has been fixed in Delphi 2, I believe.
Mark
Mark Williams M...@polyhdrn.demon.co.uk
Polyhedron Software Ltd.
Programs for Programmers - QA, Compilers, Graphics
************ Visit our Web site on http://www.polyhedron.co.uk/ ************