is record locked?

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
EarlyBird
Posts: 16
Joined: Thu 02 Dec 2010 08:54

is record locked?

Post by EarlyBird » Thu 02 Dec 2010 09:12

Hello,
In my multiuser application i need to check whether a record is being edited by user.
I need this before a other user can start to edit the record.
I whant to show a message that the record is in use by a user.
How can i do this?

Thanks for help
EarlyBird

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Thu 02 Dec 2010 10:15

hello,

To do this you can use the TOraQuery.LockMode and TOraQuery.CheckMode properties, for example:

OraQuery1.LockMode := lmLockImmediate;
OraQuery1.CheckMode := cmException;

in this case users will get an error message when trying to modify a record that was used already.

For more information please see the TOraDataSet.LockMode Property and the TOraDataSet.CheckMode Property topics in the ODAC help.

EarlyBird
Posts: 16
Joined: Thu 02 Dec 2010 08:54

Post by EarlyBird » Thu 02 Dec 2010 11:20

Hi,
thanks for quick response.
I tryed your solution.
It works .
But i need a little more information for the User.
Is there a event fired if i try to edit a locked record?
At the moment i get no message.
I only can´t edit the record.
(Thats good)
If the first user has finished editing the record and then i try to edit the record i get a message:"Record was changed by another user."
Is it possible to get my own message for this.
And last: is it possible to refresh only the changed record automaticliy?


Thanks for help

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Thu 02 Dec 2010 12:44

To create your own error message you can use the OnEditError event, for example

procedure TForm1.OraQuery1EditError(DataSet: TDataSet; E: EDatabaseError;
var Action: TDataAction);
begin
ShowMessage('Your error message');
Action:=daAbort;
end;
is it possible to refresh only the changed record automaticliy
You can use the RefreshRecord property like
OraQuery1.RefreshRecord := roBeforeEdit;

Post Reply