• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

How to check if record is locked

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.
0
tdiamond
Asked:
tdiamond
  • 2
1 Solution
 
WaldekCommented:
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;
0
 
tdiamondAuthor Commented:
What you gave me is a great start but it doesn't seem to compile (unless I'm doing something wrong). The following code works but will report an error when any kind of EDBEngineError occurs.  Can you tell me (or show me) how to modify it to test specifically for a locked record?  It would help me out a lot.

procedure TFRMMain.Button2Click(Sender: TObject);
begin
  try
    ItemsTable.edit;
    ItemsTable['Test']:=1;
  except on EDBEngineError do showmessage('Record is locked !');
  end;
end;
0
 
WaldekCommented:
check function from unit BDE : DBIIsRecordLocked
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now