Solved

How to check if record is locked (again)

Posted on 1997-12-07
4
272 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
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
Waldek earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now