Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread Table.Refresh in BeforeEdit event.
Mon, Mar 29 2010 6:40 PMPermanent Link

Adam H.

Hi Guys,

Just wondering - is there any drawback to putting a call to
Table.Refresh in a TDBISam table's BeforeEdit event?

(The idea is to eliminate the Error being raised when another user has
changed a record).

Cheers

Adam.
Tue, Mar 30 2010 2:51 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Adam


There's better way - eat the exception in the OnEditError event for the table

procedure TDM.EditError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction);
var
ID1, ID2: TBookmark;
begin
if (E is EDBISAMEngineError)
 and (EDBISAMEngineError(E).ErrorCode = DBISAM_KEYORRECDELETED)
 and (not TDBISAMTable(DataSet).RecordIsLocked) then begin
 ID1 := DataSet.GetBookmark;
 DataSet.Refresh;
 ID2 := DataSet.GetBookmark;
 if DataSet.CompareBookmarks(ID1, ID2) = 0 then Action := daRetry else begin
  MessageDlg('That record has been deleted or its ID changed', mtError, [mbOK], 0);
  Action := daAbort;
 end;
 DataSet.FreeBookmark(ID1);
 DataSet.FreeBookmark(ID2);
end else begin
 MessageDlg(E.Message, mtError, [mbOK], 0);
 Action := daAbort;
end;
end;

Roy Lambert [Team Elevate]
Tue, Mar 30 2010 2:51 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Adam,

<< Just wondering - is there any drawback to putting a call to Table.Refresh
in a TDBISam table's BeforeEdit event? >>

Performance, mostly.  You only want to refresh when you know that you need
to, and the best solution is what Roy indicated in his response.

--
Tim Young
Elevate Software
www.elevatesoft.com

Tue, Mar 30 2010 5:56 PMPermanent Link

Adam H.

Beautiful... thanks guys, appreciate the feedback and the code example!

Cheers

Adam.
Wed, Mar 31 2010 2:44 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Adam


Nada. I think the code, or something very like it, was nicked from the DBISAM manual to start with anyway.

Roy Lambert
Mon, Apr 5 2010 8:06 PMPermanent Link

Adam H.

Hey Roy and Tim,

> Nada. I think the code, or something very like it, was nicked from the DBISAM manual to start with anyway.

That's what makes a good developer in my opinion... CTRL+C and CTRL+V  Wink


In regards to the code - I'm hoping to put this throughout my entire
application so I don't need to do this per table. (We're talking
hundreds of TTable Components on over a hundred different forms)

I have a couple of different ideas on how to do this, and wanted to run
them by you guys incase you can see problems with them, or your comment
on what would be the best to go with:

IDEA 1: Ancestor Form.

Have a ancestor form for all forms within the application. In the form's
OnCreate event I loop through all components and find all TDBISamTable
components and set the TicketTEditError to point to a procedure on the
ancestor form.



IDEA 2: TDBISamTable Descendent component.

Design a component that's a decendent of the TDBISamTable that has this
feature automatically built into it. (Maybe create a new property on the
component called something like "RefreshBeforeEdit" which has the code
you provided 'built in' to the component).


IDEA 3: Request Tim to have a property such as "RefreshBeforeEdit" built
into the next release of DBISam instead. Wink


Just wondering what your thoughts are?

Cheers

Adam.
Tue, Apr 6 2010 2:22 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Adam


Go for Idea 2

Roy Lambert
Tue, Apr 6 2010 2:36 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Adam,

<< IDEA 1: Ancestor Form.

Have a ancestor form for all forms within the application. In the form's
OnCreate event I loop through all components and find all TDBISamTable
components and set the TicketTEditError to point to a procedure on the
ancestor form. >>

That's probably the best solution since it offers the ability to do
something different if you need to, for example, display a message to the
user, or get their input before proceeding.

Case in point, this is the code for the common OnEditError handler in the
DBSYS utility:

procedure TMainForm.WindowEditError(DataSet: TDataSet; E: EDatabaseError;
                                   var Action: TDataAction);
begin
  Action:=daAbort;
  if (E is EDBISAMEngineError) then
     begin
     if (EDBISAMEngineError(E).ErrorCode=DBISAM_RECLOCKFAILED) then
        begin
        if MessageDlg('The record you are trying to edit is currently
locked, '+
                      'do you want to try to edit this record again?',
                      mtWarning,[mbYes,mbNo],0)=mrYes then
           Action:=daRetry;
        end
     else if (EDBISAMEngineError(E).ErrorCode=DBISAM_LOCKED) then
        begin
        if MessageDlg('The table you are trying to edit is currently
locked, '+
                      'do you want to try to edit this record again?',
                      mtWarning,[mbYes,mbNo],0)=mrYes then
           Action:=daRetry;
        end
     else if (EDBISAMEngineError(E).ErrorCode=DBISAM_KEYORRECDELETED) then
        begin
        MessageDlg('The record you are trying to edit has been modified
since '+
                   'it was last retrieved, the record will now be
refreshed',
                   mtWarning,[mbOk],0);
        DataSet.Refresh;
        Action:=daRetry;
        end
     else
        MessageDlg(E.Message,mtError,[mbOK],0);
      end
  else
     MessageDlg(E.Message,mtError,[mbOK],0);
end;

--
Tim Young
Elevate Software
www.elevatesoft.com


Image