Page 1 of 1

Change Record

Posted: Tue 13 Nov 2012 23:51
by siberya
Hello,

I'm trying to disconnect mode

TDataSet.CachedUpdates = True
TCustomDADataSet.FetchAll = True
TCustomDADataSet.Options.LocalMasterDetail = True
AutoCommit = True

How do I know if a record has been changed by another user?

Thanks.

Re: Change Record

Posted: Wed 14 Nov 2012 11:33
by AndreyZ
Hello,

There is no way to determine if a record has been changed by another user in the cached mode. But it is possible to prevent a record to be modified by another user in the non-cached mode using the locking engine. Here is a code example that demonstrates this:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  IBCQuery1.Connection := IBCConnection1; // IBCConnection1 represents the first user
  IBCQuery1.LockMode := lmLockImmediate; // locking is performed when the user starts editing a record
  IBCQuery1.SQL.Text := 'select * from dept';
  IBCQuery1.Open;
  IBCQuery1.Edit; // here the record is locked

  IBCQuery2.Connection := IBCConnection2; // IBCConnection2 represents the second user
  IBCQuery2.LockMode := lmLockImmediate;
  IBCQuery2.SQL.Text := 'select * from dept';
  IBCQuery2.Open;
  IBCQuery2.Edit; // here the 'Lock conflict' error occurs because this record is already being modified by the first user
end;

Re: Change Record

Posted: Thu 15 Nov 2012 01:29
by siberya
Thank you for your response.

Is it possible to make something using post_event with cached mode? Can you tell me what you think?

Re: Change Record

Posted: Thu 15 Nov 2012 09:45
by AndreyZ
Using post events, you will be able to determine that some data in a table was changed. You will not be able to determine a particular record that was changed. If you are interested to determine if any data in a table was changed, you can use the TIBCAlerter component. Using TIBCAlerter, you can handle events to respond to actions and database changes made by other applications. You can find an example of using TIBCAlerter within IBDAC demos.