Board index » delphi » Current record modified?

Current record modified?

Hi everybody!

  I've posted this question before but got no respones. My problem is the
following:
Assume you have a form with a TTable control and several (not necessarily
data-aware) controls displaying data from the current record. After some
time the user decides to edit the data. In the meanwhile, however, some
other user in the network may have edited or even deleted the current record
and consequently the data displayed may not be up to date any more. In that
case, I would like to inform the user of the changes before an attempted
edit. So I would need something like

function RecordIsUpToDate(t: TTable): boolean;

so that I could check whenever I want. I tried the following:

function RecordIsUpToDate(t: TTable): boolean;
begin
  Result:=true;     {innocent until proven guilty}
  try
    t.Edit;
    t.Post;         {do a dummy edit}
  except
    Result:=false;  {quite crude, I know}
    t.Cancel;
  end;
end;

  However, this does not work as I expected. On Interbase tables the dummy
edit produces all kinds of strange errors like violations of CHECK
constraints of the underlying table (Why!? The record must have been valid
before and I did not do anything to change it!). Also, I guess there are
other, probably more inteligent methods to write a function that serves the
purpose described above. So, if anybody out there could give me an advice
how to do that, I'd be extremely greatful.

Thanks in advance for any comment,

                                                Andy

 

Re:Current record modified?


Quote
atroe...@nelly.mat.univie.ac.at (Andreas Troester) wrote:
>Hi everybody!

>  I've posted this question before but got no respones. My problem is the
>following:
>Assume you have a form with a TTable control and several (not necessarily
>data-aware) controls displaying data from the current record. After some
>time the user decides to edit the data. In the meanwhile, however, some
>other user in the network may have edited or even deleted the current record
>and consequently the data displayed may not be up to date any more. In that
>case, I would like to inform the user of the changes before an attempted
>edit.

The "dirty" way of doing this would be by refreshing your result-set
periodically, by using a timer probably. However, this isn't
bullet-proof and the probability of an error increases with the number
of users.

What you should do is implement a callback. It's much too long and
complicate to explain here (probably the cause of your not getting an
answer), but take a look at the BDE help: look for DbiGetCallBack and
DbiRegisterCallBack in particuliar. Or take a look at DBITYPES.INT in
\Delphi\Doc.

There's a series of articles running on the subject in the Delphi
Magazine, BTW. Issue 5, Jan. 1996 deals with this topic on 5 pages
with example source-code.

Cheers!

Jasper

PS: please take into consideration
- when replying, I just think I know;
- when asking, be sure that I don't.

Re:Current record modified?


I've asked about such problem in this conference too, but get not any response too.
But I've some solution of this problem.
The  strategy is next: SQL Server must send message to clients about changes in
table and client apps have special component, which understand such messages and
firing
          UpdatedTable.Refresh;          .
  This mechanism guaranteed, that any time client app has fresh data.
The realisation of such mechanism depends on your SQL Server. If you use
InterBase you can simply use Event Alerters. If you use MS SQL (as I am) or
other SQL, you can develope extended stored procedure, which will send message
about changes in any table to every client application.
  We've almost develope such one, which will send IPX messages. And we'll
develope special Delphi component which will receive such messages and
refresh accorded tables in client app.
      If you have any good thoughts on this topic I'll be glad to knew
about them.

      Good Luck!
      Vlad Matveyev

Re:Current record modified?


On 13 Mar 1996, Andreas Troester wrote:

Quote
> Hi everybody!

>   I've posted this question before but got no respones. My problem is the
> following:
> Assume you have a form with a TTable control and several (not necessarily
> data-aware) controls displaying data from the current record. After some
> time the user decides to edit the data. In the meanwhile, however, some
> other user in the network may have edited or even deleted the current record
> and consequently the data displayed may not be up to date any more. In that
> case, I would like to inform the user of the changes before an attempted
> edit. So I would need something like

> function RecordIsUpToDate(t: TTable): boolean;

> so that I could check whenever I want. I tried the following:

> function RecordIsUpToDate(t: TTable): boolean;
> begin
>   Result:=true;     {innocent until proven guilty}
>   try
>     t.Edit;
>     t.Post;         {do a dummy edit}
>   except
>     Result:=false;  {quite crude, I know}
>     t.Cancel;
>   end;
> end;

>   However, this does not work as I expected. On Interbase tables the dummy
> edit produces all kinds of strange errors like violations of CHECK
> constraints of the underlying table (Why!? The record must have been valid
> before and I did not do anything to change it!). Also, I guess there are
> other, probably more inteligent methods to write a function that serves the
> purpose described above. So, if anybody out there could give me an advice
> how to do that, I'd be extremely greatful.

> Thanks in advance for any comment,

>                                                 Andy

What about checking TTable.State property?

Result:=t is [dsEdit,dsInsert];

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$                                                                     $
$ Kazda cywilizacja musi dojsc do momentu, w ktorym wymysli PIWO!     $
$                                                                     $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
K@M

end of signature

Re:Current record modified?


In <Pine.SOL.3.91.960318163033.23223B-100...@roger03.elka.pg.gda.pl>

Quote
Wojciech Kromer <c5562...@cs-boglab.elka.pg.gda.pl> writes:

>On 13 Mar 1996, Andreas Troester wrote:

>> Hi everybody!

>>   I've posted this question before but got no respones. My problem
is the
>> following:
>> Assume you have a form with a TTable control and several (not
necessarily
>> data-aware) controls displaying data from the current record. After
some
>> time the user decides to edit the data. In the meanwhile, however,
some
>> other user in the network may have edited or even deleted the
current record
>> and consequently the data displayed may not be up to date any more.
In that
>> case, I would like to inform the user of the changes before an
attempted
>> edit. So I would need something like

>> function RecordIsUpToDate(t: TTable): boolean;

>> so that I could check whenever I want. I tried the following:

>> function RecordIsUpToDate(t: TTable): boolean;
>> begin
>>   Result:=true;     {innocent until proven guilty}
>>   try
>>     t.Edit;
>>     t.Post;         {do a dummy edit}
>>   except
>>     Result:=false;  {quite crude, I know}
>>     t.Cancel;
>>   end;
>> end;

>>   However, this does not work as I expected. On Interbase tables the
dummy
>> edit produces all kinds of strange errors like violations of CHECK
>> constraints of the underlying table (Why!? The record must have been
valid
>> before and I did not do anything to change it!). Also, I guess there
are
>> other, probably more inteligent methods to write a function that
serves the
>> purpose described above. So, if anybody out there could give me an
advice
>> how to do that, I'd be extremely greatful.

>> Thanks in advance for any comment,

>>                                                 Andy

How about calling the refresh method before.  You can either add
Table1.Refresh to the onBeforeEdit event of tTable or adding this line
once you put the table in edit mode.  Keep in mind for the second
method it is only safe if AutoEdit is set to false.

Ben
Arrow

Re:Current record modified?


Hi everybody!

My latest amateur research confirms that my first approach to the problem
below should work, at least for SQL databases, in part also for Paradox (?).
Let's see what I wrote a week ago:

: Hi everybody!

:   I've posted this question before but got no respones. My problem is the
: following:
: Assume you have a form with a TTable control and several (not necessarily
: data-aware) controls displaying data from the current record. After some
: time the user decides to edit the data. In the meanwhile, however, some
: other user in the network may have edited or even deleted the current record
: and consequently the data displayed may not be up to date any more. In that
: case, I would like to inform the user of the changes before an attempted
: edit. So I would need something like

: function RecordIsUpToDate(t: TTable): boolean;

: so that I could check whenever I want. I tried the following:

: function RecordIsUpToDate(t: TTable): boolean;
: begin
:   Result:=true;     {innocent until proven guilty}
:   try
:     t.Edit;
:     t.Post;         {do a dummy edit}
:   except
:     Result:=false;  {quite crude, I know}
:     t.Cancel;
:   end;
: end;

**** This should at least produce an EDatabaseError exception if the
underlying record got deleted in the meantime ("Record/key deleted") -
so you can easily set up a trap for it. I still do not now what kind of
exception is raised, however, if the record is only edited but not deleted.
The reason is the following:
For SQL databases, it is raised (at least according to the manual) if the
underlying table has UpdateMode set to  "WhereAll" (I hope I remember
correctly because there is no Delphi installed on the machine I am working on
now). However, since I only have the LOCAL Interbase at my disposal, I was
unable to provoke this situation. With Paradox, if somebody else modifies the
data no exception seems to be raised in this case, regardless of how you
set UpdateMode.

:   However, this does not work as I expected. On Interbase tables the dummy
: edit produces all kinds of strange errors like violations of CHECK
: constraints of the underlying table (Why!? The record must have been valid
: before and I did not do anything to change it!).

*** I was wrong! The data were indeed NOT valid even before the edit!
How can this happen? What you have to do is first import data to an Interbase
table and LATER impose additional check constraints on the table. I naively
thought that imposing these check conditions would fail if an existing
record violates one of them. However, this is obviously NOT true!

: Also, I guess there are
: other, probably more inteligent methods to write a function that serves the
: purpose described above. So, if anybody out there could give me an advice
: how to do that, I'd be extremely greatful.
:  
*** Yep. Check out the followup of Jasper Stil to this discussion, to whom my
special thanks go (for this one and many others).

: Thanks in advance for any comment,

*** Same story.

                                                 Andy

Other Threads