SQLMemTable: Embedded BDE Alternative
In-Memory SQL Database for Delphi / C++Builder



Sorting records
Previous  Top  Next


Introduction

You may use the IndexName and IndexFieldNames properties to set the current index order, and consequently, sort the current table based upon the index definition for the selected index order. The IndexName property is used to set the name of the current index. If this property is set to blank ('') records are not sorted and shown in physical order. The following example shows how you would set the current index order to an index called CustomerName:

begin
with MySQLMemTable do
begin
IndexName:='CustomerName';
do something
end;
end;

Please note that changing the index order can cause the current record pointer to move to a different position in the table (but not necessarily move off of the current record unless the record has been changed or deleted by another user), so please be sure to call the
First method after setting the IndexName property if you want to have the record pointer set to the beginning of the table based upon the next index order. Since the logical record numbers are based upon the index order the record number may also change. If you attempt to set the IndexName property to a non-existent index an exception will be raised.
The
IndexFieldNames property is used to set the current index order by specifying the field names of the desired index instead of the index name. Multiple field names should be separated with a semicolon. Using the IndexFieldNames property is desirable in cases where you are trying to set the current index order based upon a known set of fields and do not have any knowledge of the index names available. The IndexFieldNames property will attempt to match the given number of fields with the same number of beginning fields in any of the available primary or secondary indexes. The following example shows how you would set the current index order to a secondary index called CustomerName that consists of the CustomerName field and the CustomerNo field:

begin
with MySQLMemTable do
begin
IndexFieldNames:='CustomerName;CustomerNo';
do something
end;
end;

Please note that if SQLMemTable cannot find any indexes that match the desired field names an exception will be raised. If you are using this method of setting the current index order you should also be prepared to trap for this exception and deal with it appropriately.


© AidAim Software SQLMemTable: In-memory Sql Database Delph