Board index » delphi » Responding to changes in underlying database with a TTable/TQuery

Responding to changes in underlying database with a TTable/TQuery

I have a project where users create/edit records on non-modal forms (like
MDI but with the windows appearing on the taskbar a la MS outlook). I also
have a main form which displays summary data. Forms are created dynamically
and I've set up a set of routines providing a message dispatching system to
the whole software : when a form posts data it calls a routine
DoDatabaseChange and passes an Id number for the table and the value of the
table's key field for the record that has changed. DoDatabaseChange then
dispatches that to all the windows that have registered to receive updates
for the relevant table.

That all works OK but my problem is in handling the database changed
message. I was assuming that TTable.Refresh would update the dataset from
disk, but it doesn't seem to work. After calling the routine the changes
haven't appeared, though they are present in the database underneath
(verified by viewing the db in database desktop as I step through).

As far as I can see, the only way to reload the data is an
Active:=False/Active:=True pair - is that right? It strikes me that may be
slow if done regularly.... also if I do have to do that, how can I keep the
record being viewed as current? Is there an easier way than copying the key
value and doing a locate after re-opening the dataset?

Any opinions welcome

Andrew

 

Re:Responding to changes in underlying database with a TTable/TQuery


Are the fields lookups to another table?  If so, Refresh doesn't seem to
refresh lookups.  Call the RefreshLookupLists instead.

With Table1 do
      For i:=0 to FieldCount -1 do
        If (Fields[i]).FieldKind=fkLookup then
            (Fields[i]).RefreshLookupList;

In regards to your locating the record after an open/close.. refer to
TBookmark in the Delphi help.

Re:Responding to changes in underlying database with a TTable/TQuery


Andrew,
I had this as well in a similar situation
If it's on the same machine, then try a repaint on the target window(s), in
case it's just not redrawing to show the new data, and Processmessages to
make sure it gets done.
If it's on different machines (or maybe anyway) set the dreaded "Local
Share=True" setting in BDE
HTH
Chris Hearn

Quote
"Andrew Coulton" <newkiebr...@free4internet.com> wrote in message

news:3afa81ca_1@dnews...
Quote
> I have a project where users create/edit records on non-modal forms (like
> MDI but with the windows appearing on the taskbar a la MS outlook). I also
> have a main form which displays summary data. Forms are created
dynamically
> and I've set up a set of routines providing a message dispatching system
to
> the whole software : when a form posts data it calls a routine
> DoDatabaseChange and passes an Id number for the table and the value of
the
> table's key field for the record that has changed. DoDatabaseChange then
> dispatches that to all the windows that have registered to receive updates
> for the relevant table.

> That all works OK but my problem is in handling the database changed
> message. I was assuming that TTable.Refresh would update the dataset from
> disk, but it doesn't seem to work. After calling the routine the changes
> haven't appeared, though they are present in the database underneath
> (verified by viewing the db in database desktop as I step through).

> As far as I can see, the only way to reload the data is an
> Active:=False/Active:=True pair - is that right? It strikes me that may be
> slow if done regularly.... also if I do have to do that, how can I keep
the
> record being viewed as current? Is there an easier way than copying the
key
> value and doing a locate after re-opening the dataset?

> Any opinions welcome

> Andrew

Re:Responding to changes in underlying database with a TTable/TQuery


Quote
> In regards to your locating the record after an open/close.. refer to
> TBookmark in the Delphi help.

Didn't I read somewhere that a bookmark is only valid for that table while
it is open, and closing and re-opening it invalidates the bookmark?

Or was that the Delphi help just being over cautious?

--Bill Sparrow--
Member of the UK Borland User Group

Re:Responding to changes in underlying database with a TTable/TQuery


Bill,

The TBookMark works fine after Open/Closing -- made sure by testing
this morning.

John

Quote
"Bill Sparrow" <bsparrowXsp...@cix.co.uk> wrote in message

news:memo.20010511155406.121C@bsparrow.compulink.co.uk...
Quote
> > In regards to your locating the record after an open/close.. refer to
> > TBookmark in the Delphi help.

> Didn't I read somewhere that a bookmark is only valid for that table while
> it is open, and closing and re-opening it invalidates the bookmark?

> Or was that the Delphi help just being over cautious?

> --Bill Sparrow--
> Member of the UK Borland User Group

Re:Responding to changes in underlying database with a TTable/TQuery


Quote
John Easley wrote in message <3afc07ea_1@dnews>...

>The TBookMark works fine after Open/Closing -- made sure by testing
>this morning.

It will likely always work on a single user system, and will still
work *most* of the time even when there are multiple users - but that
is where you can run into trouble. Bookmarks are *not* guaranteed over
a close and open of a TQuery or TTable.

--
Wayne Niddery (WinWright Inc.)
RADBooks - http://members.home.net/wniddery/RADBooks/delphibooks.html
"At the apex of every great tragedy of mankind there stands the figure
of an incorruptible altruist" - Ayn Rand

Other Threads