AnyDAC offers few methods to find a specific record in the dataset.
All AnyDAC datasets are offering few approaches to find a record in a local dataset records cache. Depending on the current sorting, the record search may be optimized.
AnyDAC datasets offer few options to locate a record or lookup a value for a specified key. These method may use the current dataset index, if it is appropriate for the method call.
ADQuery1.IndexFieldNames := 'ORDERID'; if ADQuery1.Locate('ORDERID', 10150, []) then ShowMessage('Order is found') else ShowMessage('Order is not found');
AnyDAC datasets offer few extended methods to locate a record. These method may use the current dataset index, if it is appropriate for the method call.
if ADQuery1.LocateEx('Price >= 1000 and Price <= 2000', []) then ShowMessage('Order is found') else ShowMessage('Order is not found');
This approach to locate a record was introduced into AnyDAC for compatibility with BDE components. It may be completely replaced with LocateEx method. The approach is using the methods:
To start a search the application must specify predicate as a boolean expression in the Filter property. Note, that this method cannot be used to locate a record in a filtered dataset. Also, the filter is not activated and is used only for locating a record. For example:
ADQuery1.Filter := 'Price >= 1000 and Price <= 2000'; if ADQuery1.FindFirst then ShowMessage('Found !'); ... if ADQuery1.FindNext then ShowMessage('Found !');
This approach to locate a record was introduced into AnyDAC for compatibility with BDE components. But we found it helpful. The approach is using the methods:
Before calling these methods the current index must be set. For example:
ADQuery1.IndexFieldNames := 'ORDERID';
ADQuery1.SetKey;
ADQuery1.FieldByName('ORDERID').AsInteger := 10150;
if ADQuery1.GotoKey then
ShowMessage('Order is found')
else
ShowMessage('Order is not found');
Most of the search methods are returning True, when a record is found. Alternatively application may check the dataset Found property.
Also note, AnyDAC does not support locating on fields of the fkCalculated and fkLookup kinds. But application may use fkInternalCalc and fkAggregate fields in locating.
|
What do you think about this topic? Send feedback!
|