Board index » delphi » TTable Question

TTable Question

I have an application with a TTable component on the main form and a
TTable component on a sub form.

While the TTable component on the main form is active I show the sub
form and activate its TTable component.

The TTable components on both forms have the same database active at the
same time.

For some reason, when I add a record to the database using the sub form,
the new record does not show up in the DBGrid on my main form unless I
shut the application down and restart it (closing/re-opening the db
isn't sufficient).

Further confusing is that it only affects the first record I add... I
create a database in the main form and then show (modally) the sub
form... database on main form is still active.  I then activate the
TTable component on my sub form, append a record, post my changes, and
return to the main form... it isn't updated (even though I have issued a
TTable1.Refresh).  However, once the app has been shut down and
restarted, the first record I added appears and the problem no longer
exists... as additional records are added they appear in the DBGrid1 on
my main form immediately after I execute the TTable1.Refresh.

I am doing a TTable1.Refresh on the main form once the sub form has
added the record and closed its TTable component.

Any idea on how I can get the DBGrid in my main for to properly update
after I have added the first record via the data entry screen I have on
my sub form?

-- Paul
-- poli...@airmail.net
-- This stuff I'm makin' up is true!

 

Re:TTable Question


In article <324F2DC7.7...@airmail.net> "Paul J. Polillo" <poli...@airmail.net> writes:

Quote
>From: "Paul J. Polillo" <poli...@airmail.net>
>Subject: TTable Question
>Date: Sun, 29 Sep 1996 21:17:44 -0500
>I have an application with a TTable component on the main form and a
>TTable component on a sub form.
>While the TTable component on the main form is active I show the sub
>form and activate its TTable component.
>The TTable components on both forms have the same database active at the
>same time.
>For some reason, when I add a record to the database using the sub form,
>the new record does not show up in the DBGrid on my main form unless I
>shut the application down and restart it (closing/re-opening the db
>isn't sufficient).
>Further confusing is that it only affects the first record I add... I
>create a database in the main form and then show (modally) the sub
>form... database on main form is still active.  I then activate the
>TTable component on my sub form, append a record, post my changes, and
>return to the main form... it isn't updated (even though I have issued a
>TTable1.Refresh).  However, once the app has been shut down and
>restarted, the first record I added appears and the problem no longer
>exists... as additional records are added they appear in the DBGrid1 on
>my main form immediately after I execute the TTable1.Refresh.
>I am doing a TTable1.Refresh on the main form once the sub form has
>added the record and closed its TTable component.
>Any idea on how I can get the DBGrid in my main for to properly update
>after I have added the first record via the data entry screen I have on
>my sub form?
>-- Paul
>-- poli...@airmail.net
>-- This stuff I'm makin' up is true!

Paul:

You could have both forms use the same ttable component!.  You could declare
it on the main form and attach the datasource to it.  Then attach all main
form fields to that datasource.

On the sub form, declare a datasource and leave the dataset property blank.  
Go ahead and set up the fields on the sub form and point them to this
datasource.

In the code for the sub form, after the implementation declaration, place a
"uses <main form>" statement, substituting the main form name for <main form>.

Then in the activation method of the sub form, set the datasource.dataset
property to <main form>.tablename.  (not sure of the exact syntax here - have
it at home if you need it).  

That should do what you want and be a whole lot cleaner.  Of course, on D2 it
is even simpler.

-Dave

Other Threads