Solved

How to check if record is locked (again)

Posted on 1997-12-07
4
275 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
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 100
Help on project with Soap 10 54
Print Graphic and Text to Epson TM-T88v 12 260
Error E2158 compiling with Delphi XE10 Seattle 2 100
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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