Board index » delphi » multiuser file/record locking question

multiuser file/record locking question

I'm using Delphi 1.0 in a multi-user environment and need to trap a "record in
use" exception that allows the program to just wait until the record is
available and then procede as normal.

If you can help I would appreciate it,

Tony Power

 

Re:multiuser file/record locking question


Hello,
  Here's an example.  I think the ErrorCode is 1024...not positive
though.  You could find it when this message pops up.

   try
      case iTableType of
         PUBS_ID                : DMRhino.tblPubs.edit;
         FORMS_ID       : DMRhino.tblForms.edit;
         SERIES_ID      : DMRhino.tblSeries.edit;
         TRACKING_ID    : DMRhino.tblTrack.edit;
         O_PUBS_ID      : DMRhino.tblPubs.edit;
         O_FORMS_ID     : DMRhino.tblPubs.edit;
      end;

{catch recordlocking exception and handle notifying user to try again
at a later and more convienent time for the master database}

   except on E:EDBEngineError do
      begin
         Application.CreateForm(TfrmError, frmError);
         frmError.Memo1.lines.clear;

         for cnt := 0 to E.Errorcount-1 do
            frmError.Memo1.lines.add(IntToStr(E.Errors[cnt].ErrorCode)
                                + ' -- ' + E.Errors[cnt].Message);

         frmError.Memo1.lines.add('There was an error with your
                                database modification request.');

         frmError.Memo1.lines.add('Please try again later.');

         frmError.showmodal;
         frmError.release;
      end;
   end;

=======================
You can look at the EDBEngineError Exception class and get the
details.  The E instantiation gives you access to all the properties
of the exception one of which is ErrorCode.

In order to get the thing to wait until the record is unlocked, you
could modify this a little and in the exception handling area keep
trying to open the table, or put the whole thing in a while loop.

Hope this helps,
Jeff
-----

Quote
cen02...@centuryinter.net wrote:
>In <4mqip9$...@news.nstn.ca>, dmo...@fox.nstn.ca (Tony Power) writes:
>>I'm using Delphi 1.0 in a multi-user environment and need to trap a "record in
>>use" exception that allows the program to just wait until the record is
>>available and then procede as normal.

>>If you can help I would appreciate it,

>>Tony Power

>The record is locked when an edit operation is done on it.  Use TRY before
>the edit and EXCEPT after it.  There is a particular exception that is
>triggered when the record cannot be locked.  I'm not right in from of my
>stuff right now, so I don't remember the name of the exception.  I found it by
>running a program that edited a record (and therefore locking it) and then ran
>the same program again and tried to edit the same record.  The second
>instance of the program halted with a message about the exception and
>gave the name of the exception right there.  This is what would go in the
>ON exception DO statements section.
>Hope this helps.
>Bob

Other Threads