BCS Delphi XE8 Database Navigation


There are those time when you will need to traverse databases to attain the desired information.
dbs
The BCS Delphi XE8 Database Navigation tool will allow you to traverse to your hearts content.

{*-----------------------------------------------------------------------------
 Procedure: DBPos
 Author: Mr. Arch Brooks, Software Engineer, Brooks Computing Systems LLC
 Date: 19-Aug-2015
 @Param dbn: TDBNavigator; sfn: String
 @Return None
-----------------------------------------------------------------------------}
 
Procedure TBCSPwbC.DBPos(dbn: TDBNavigator; sfn: String);
var
  pb: String;
  cp: String;
begin
  pb := InputBox('Enter Starting Position!', 'Where Do I Start!', '');
  if Trim(pb) = '' then
  begin
    MessageBox(Handle, 'You want to search with a nill string!',
      'No Search Available!', mb_OkCancel);
    exit;
  end;
  cp := dbn.DataSource.Dataset.FieldByName(sfn).AsString;
  if pb < cp then
  begin
    repeat
      dbn.DataSource.Dataset.Prior;
    until ((pb >= dbn.DataSource.Dataset.FieldByName(sfn).AsString) or
      (dbn.DataSource.Dataset.RecNo = 1));
  end
  else
  begin
    repeat
      dbn.DataSource.Dataset.Next;
    until ((dbn.DataSource.Dataset.FieldByName(sfn).AsString >= pb) or
      (dbn.DataSource.Dataset.Eof));
  end;
  cp := cp;
end;

When I observed the scenario I determined the common denominator was the database navigator and a key string field.

In addition to traversing forward the capability to traverse in a backwards direction was also desirable.  Upon initial testing a loop occurred so I determined the logic of the routine would have to detect the start and end of the data set.  The logic was also put into place that determined direction of the search depending on the search key criteria.

If the key was less than the current database position the search would be in a backwards direction.  Conversely if the key was greater then the database position the search would in a forward direction. This handy utility works for any data table connected to database navigator TDBNavigator.

The source code may be found by clicking here.

Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored
this article.

Leave a Reply