Board index » delphi » How do I trap locked record exceptions?

How do I trap locked record exceptions?

I have a page of DB aware text controls on a page. They are attached to a
datasource that is, in turn, attached to a TTable in a dataModule. If you
try to edit a locked record, you get an error dialog that, I assume, is from
the Tapplication level.

How do I trap it at the form level? Or do I have to continually change
application.OnException each time a different form gets focus?

Thanks,

Jim Margarit
jmarga@lascrucesDOTcom

 

Re:How do I trap locked record exceptions?


Quote
Jim Margarit wrote in message <72dmfa$a...@forums.borland.com>...
>I have a page of DB aware text controls on a page. They are attached to a
>datasource that is, in turn, attached to a TTable in a dataModule. If you
>try to edit a locked record, you get an error dialog that, I assume, is
from
>the Tapplication level.

>How do I trap it at the form level? Or do I have to continually change
>application.OnException each time a different form gets focus?

>Thanks,

>Jim Margarit
>jmarga@lascrucesDOTcom

From your message I'm not sure how many tables or forms are involved, how
many of the controls share the same table component or how you are
controlling the attempt to enter edit on a record so this may or may not
help you.

Assuming table1 is on a datamodule
datamodule.name := dm;
the state of table1 is dsbrowse

procedure someproc;
begin
{
some user action indicates a need or want to enter edit on a particular
record

Quote
}

  try
    dm.table1.edit;  // this trys to put the table in edit on the current
record
  except       // if it is already being edited or not available for some
reason we get an exception
   on edatabaseerror do  // could trap for other exceptions besides
databaseerrors
    raise;      // won't get fancy just raise the default exception so the
user get an error message
  end;          // they have to respond to

end;

Hope this helps
Wes

Re:How do I trap locked record exceptions?


Jim,

I write a lockrecord function into each of my programs to handle the
EDataBaseException.  Then I just send the table to the function each time I
want to edit  and handle the exception.

Briefly you could do something like this:

function TForm1.LockRecord( aTable: TTable ): Boolean;
begin

 try

 aTable.Edit;

except
 on E:DataBaseError do begin
  // show the error
  ShowMessage( E.Message) or
  MessageDlg( E.Message...)

  // then decide what to do i.e. loop or fail etc.
 end;
end;

end;

You could enclose the try - except in a repeat until loop to give the user a
chance to wait and try again, or Break to get out.

Rick

Quote
Jim Margarit wrote in message <72dmfa$a...@forums.borland.com>...
>I have a page of DB aware text controls on a page. They are attached to a
>datasource that is, in turn, attached to a TTable in a dataModule. If you
>try to edit a locked record, you get an error dialog that, I assume, is
from
>the Tapplication level.

>How do I trap it at the form level? Or do I have to continually change
>application.OnException each time a different form gets focus?

>Thanks,

>Jim Margarit
>jmarga@lascrucesDOTcom

Re:How do I trap locked record exceptions?


Quote
Jim Margarit wrote in message <72dmfa$a...@forums.borland.com>...
>I have a page of DB aware text controls on a page. They are attached to a
>datasource that is, in turn, attached to a TTable in a dataModule. If you
>try to edit a locked record, you get an error dialog that, I assume, is
from
>the Tapplication level.

>How do I trap it at the form level? Or do I have to continually change
>application.OnException each time a different form gets focus?

>Thanks,

>Jim Margarit
>jmarga@lascrucesDOTcom

I experimented today with using the application.OnException.  It seems to
work the way I want. The user can view the data and not get an error unless
they try to edit the busy record and I can give them a more friendly message
than the standard vcl dialog.

On the other hand, how do you present up to date information for them to
view/edit? Say the record lock has just been released and they can now edit.
What are they editing? Old readonly data or newly posted data?

Obviously, it's the first time I've programmed this way. I usually lock the
record, fill the fields manually, and unlock when I'm done with the record.
Other users couldn't view the data while it was being edited.  I'm trying to
be less 'non-db control' oriented and reduce some to the tedious programming
chores. It just seems to open a different can of worms.

Thanks,

Jim Margarit
jmarga@lascrucesDOTcom

Other Threads