Solved

How to check if record is locked (again)

Posted on 1997-12-07
4
278 Views
Last Modified: 2010-04-04
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(Sender: 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.
0
Comment
Question by:tdiamond
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
Waldek earned 100 total points
ID: 1353069
Sorry , in program You must use BDE function DBIIsRecordLocked(hCursor:hDBICur; var bLocked: Bool) if bLocked is set to true then record is locked. Greeting
0
 

Author Comment

by:tdiamond
ID: 1353070
I found it but I'm having a little trouble implementing it correctly.  Could you possibly give me an example of how it might be called and with what parameters?  For instance, here is what my code lookes like:

procedure TFRMMain.ButtonClick(Sender: TObject);
var
  b: bool;
begin
  DbiIsRecordLocked(ItemsTable.handle, b);
  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?
0
 
LVL 2

Expert Comment

by:Waldek
ID: 1353071
Check this
var b: bool;
begin
  Check(DbiIsRecordLocked(ItemsTable.handle, b));
     if b then
       showmessage('Record IS locked')
         else
       showmessage('Record is NOT locked');
     end;
0
 
LVL 2

Expert Comment

by:Waldek
ID: 1353072
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question