tdiamond
asked on
How to check if record is locked (again)
I submitted this question a couple of days ago:
How can you check to see whether a record that you are about to write to is locked by another user? If I have to check for an exception, then which one should I check for (EConvertError, E....)? What I want to do is rollback a Transaction if my write to a table fails.
and got this response from Waldek:
You must check for exception EDBEngineError and then
test ErrorCode like this
case Errors[0].ErrorCode of
DBIERR_LOCKED:{ Action , if lock failed}
DBIERR_UNLOCKFAILED: { Action , if unlock failed}
end;
The code doesn't compile and I was wondering if Waldek, or anybody who gets this, could help me out again?
The following code works but will report the same error when ANY kind of EDBEngineError Exception occurs. Can you tell me (or even better, show me) how to modify it to test specifically for a locked record? It would help me out a lot.
procedure TFRMMain.Button2Click(Send er: TObject);
begin
try
ItemsTable.edit;
ItemsTable['Test']:=1;
except on EDBEngineError do
showmessage('Record is locked !');
end;
end;
I want to know how I can extract the specific error condition that has occured.
How can you check to see whether a record that you are about to write to is locked by another user? If I have to check for an exception, then which one should I check for (EConvertError, E....)? What I want to do is rollback a Transaction if my write to a table fails.
and got this response from Waldek:
You must check for exception EDBEngineError and then
test ErrorCode like this
case Errors[0].ErrorCode of
DBIERR_LOCKED:{ Action , if lock failed}
DBIERR_UNLOCKFAILED: { Action , if unlock failed}
end;
The code doesn't compile and I was wondering if Waldek, or anybody who gets this, could help me out again?
The following code works but will report the same error when ANY kind of EDBEngineError Exception occurs. Can you tell me (or even better, show me) how to modify it to test specifically for a locked record? It would help me out a lot.
procedure TFRMMain.Button2Click(Send
begin
try
ItemsTable.edit;
ItemsTable['Test']:=1;
except on EDBEngineError do
showmessage('Record is locked !');
end;
end;
I want to know how I can extract the specific error condition that has occured.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Check this
var b: bool;
begin
Check(DbiIsRecordLocked(It emsTable.h andle, b));
if b then
showmessage('Record IS locked')
else
showmessage('Record is NOT locked');
end;
var b: bool;
begin
Check(DbiIsRecordLocked(It
if b then
showmessage('Record IS locked')
else
showmessage('Record is NOT locked');
end;
ASKER
procedure TFRMMain.ButtonClick(Sende
var
b: bool;
begin
DbiIsRecordLocked(ItemsTab
if (b=true) then
showmessage('Record IS locked')
else
showmessage('Record is NOT locked');
end;
It compiles, but when it runs, it always reports the record NOT being locked even when it is! Can you tell if I'm doing something wrong in my code. Am I passing the correct parameters?