Icon Setting Ranges on Tables

Setting ranges on tables is accomplished through several methods of the TEDBTable component. The basic range methods include the SetRange, SetRangeStart, SetRangeEnd, EditRangeStart, EditRangeEnd, and ApplyRange methods. The KeyColumnCount property is used with the SetRangeStart, SetRangeEnd, EditRangeStart and EditRangeEnd methods to control searching using the ApplyRange method. All range operations are dependent upon the active index order set using the IndexName or IndexFieldNames properties. Ranges may be combined with expression filters set using the Filter and Filtered propertes and/or code-based filters set using the OnFilterRow event to further filter the rows in the table.

Setting a Range
The SetRange method accepts two arrays of values to use in order to set a range on a given table. If the current row pointer does not fall into the range values specified, then the current row pointer will be moved to the nearest row that falls within the range. These value arrays must contain the column values in the same order as the column names in the active index or the range will not return the desired results. However, SetRange does not require that you fill in all of the column values for all of the columns in the active index, rather only that you fill in the column values from left to right. The following example shows how to perform a range on the index used to enforce the primary key and comprised of the CustomerNo column:

begin
   with MyTable do
      begin
      { Set to the natural order, which in this case
        is the primary key }
      IndexName:='';
      { Set a range from customer 100 to customer 300 }
      SetRange([100],[300]);
      end;
end;

The SetRangeStart, SetRangeEnd, EditRangeStart, and EditRangeEnd methods are used in conjunction with the ApplyRange method to perform a range using column assignments instead of arrays of column values. The SetRangeStart method begins the range process by putting the TEDBTable component into the dsSetKey state and clearing all column values. You can examine the state of the table using the State property. The application must then assign values to the desired columns for the start of the range and then proceed to call SetRangeEnd to assign values to the desired columns for the end of the range. After this is done the application can call the ApplyRange method to perform the actual range operation. The EditRangeStart and EditRangeEnd methods extend or continue the current range process by putting the TEDBTable component into the dsSetKey state but not clearing any column values. You can examine the state of the table using the State property. This allows you to change only one column without being forced to re-enter all column values needed for the beginning or ending values of the range. The KeyColumnCount property controls how many columns, based upon the active index, are to be used in the actual range and can be set independently for both the starting and ending column values of the range. By default the KeyColumnCount property is set to the number of columns in the active index. The following example shows how to perform a range using the SetRangeStart, SetRangeEnd, and ApplyRange methods and KeyColumnCount property. The active index is an index called "CustomerName" that consists of the CustomerName column and the CustomerNo column:

begin
   with MyTable do
      begin
      { Set to the CustomerName index }
      IndexName:='CustomerName';
      { Set a range to find all customers with
        a name beginning with 'A' }
      SetRangeStart;
      ColumnByName('CustomerName').AsString:='A';
      { This causes the range to only look at
        the first column in the current index }
      KeyColumnCount:=1;
      SetRangeEnd;      
      { Note the padding of the ending range
        values with lowercase z's
        to the length of the CustomerName
        column, which is 20 characters }
      ColumnByName('CustomerName').AsString:='Azzzzzzzzzzzzzzzzzzz';
      { This causes the range to only look at
        the first column in the current index }
      KeyColumnCount:=1;
      ApplyRange;
      end;
end;

Information In the previous example we executed a partial-column range. What this means is that we did not include all of the columns in the active index in the range. ElevateDB does not require that you use all of the columns in the active index for the range.
Image