Board index » delphi » 'Manually' Disable dbnavigator buttons

'Manually' Disable dbnavigator buttons

Hi,

For some reason I want to make my own DBNavigator buttons by
tspeedbuttons.  However I would like the 'prior' and 'first' button to
be disabled when the table cursor is actually at the first record.
Normally this isn't detected before I try to do a table1.prior when
the cursor is already at the first position.

How can I correctly and elegantly detect when the 'prior' and 'first'
buttons should have been grayed..?  (It seems not very elegant to try
with

try
  prior;
  next;
except
  btnPrior.enabled := FALSE;
end;

Thanks for any hint on this

Tor

 

Re:'Manually' Disable dbnavigator buttons


On Thu, 30 Sep 1999 14:16:53 +0200, "Tor Tveitane" <bush...@online.no>
wrote:

Quote
>For some reason I want to make my own DBNavigator buttons by
>tspeedbuttons.  However I would like the 'prior' and 'first' button to
>be disabled when the table cursor is actually at the first record.
>Normally this isn't detected before I try to do a table1.prior when
>the cursor is already at the first position.

>How can I correctly and elegantly detect when the 'prior' and 'first'
>buttons should have been grayed..?  (It seems not very elegant to try
>with

>try
>  prior;
>  next;
>except
>  btnPrior.enabled := FALSE;
>end;

I assume that this is just some sample code (because it wouldn't work
for various reasons).

There is not really a way to retrieve the information without
specifically getting after it.  TDataSet just doesn't know that it is
on the first/last record without checking at some points.  If you
don't want to use the higher-level TDataSet methods for your check,
the only alternative is to get it from the BDE directly.

Here's some example code for checking on BOF:

  function IsFirstRecord(Table: TTable): Boolean;
  var
    ErrorCode: Word;
  begin
    // synchronize physical cursor with TTable
    Table1.UpdateCursorPos;
    // check
    ErrorCode := DbiGetPriorRecord(Table.Handle, DbiNOLOCK, nil, nil);
    Result := (ErrorCode = DBIERR_BOF);
    // let TTable know we manipulated the cursor
    Table1.CursorPosChanged;
  end;

HTH,

Jan

Re:'Manually' Disable dbnavigator buttons


Hi Tor!

On Thu, 30 Sep 1999 14:16:53 +0200, "Tor Tveitane" <bush...@online.no>
wrote:

Quote
>How can I correctly and elegantly detect when the 'prior' and 'first'
>buttons should have been grayed..?  

You can check TDataSet's BOF & EOF on AfterScroll event.

tomi.

Other Threads