Board index » delphi » Using one TTable Source between Multiple Forms

Using one TTable Source between Multiple Forms

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

 

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/ ************

Re:Using one TTable Source between Multiple Forms


Mark,
Do you think it is possible to synchronise Tables across different
instances of the same application so you can display the same form twice
with the same record displayed on each? If the form is tabbed with a list
and a detail tab then 1 instance could show the list and the other could
show the detail of the record.

Regards,
David Taylor

Re:Using one TTable Source between Multiple Forms


Quote
David Taylor wrote:

> Mark,
> Do you think it is possible to synchronise Tables across different
> instances of the same application so you can display the same form twice
> with the same record displayed on each? If the form is tabbed with a list
> and a detail tab then 1 instance could show the list and the other could
> show the detail of the record.

> Regards,
> David TaylorYes,  see the GoToCurrent Proceedure for TTable.  Use the help index and look it up.

Good Luck
Evertt Byington

Other Threads