ICachedDatasetLookup.Locate

Syntax

Locate: Boolean;

Description

The Locate method searches and returns whether search in data source cache was successful.

Comments

If the search is successful, the cursor in cache is set to the found record, and the method returns True. The Lookup method is used to get field values. The cache enables the user to search only for the first record with searched field values. If the source contains more than one record with searched values, it is recommended to set up cache filtering.

Example

Executing the example requires a form and the components on it:

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    Cache: ICachedDataSet;
    CacheField: IDatasetInstanceFields;
    LookCache: ICachedDatasetLookup;
    s: String;
Begin
    Cache := UiTable1.CachedDataset;
    LookCache := Cache.CreateLookup("Field;Field1");
    CacheField := LookCache.Fields;
    CacheField.Item(0).Value := EditBox1.Text;
    CacheField.Item(1).Value := EditBox2.Text;
    If LookCache.Locate Then
        s := LookCache.Lookup("Num1").Item(0).Value As String;
    Else
        s := "Not found";
    End If;
End Sub Button1OnClick;

On the button click, the search by table cache is performed, the table is set as data source for the UiTable1 component. Search is performed between two table fields, that are Field and Field1. The searched data is contained in the EditBox1 and EditBox2 components. In case of successful search the "s" variable contains the current value of the Num1 field of the table, otherwise the variable contains the Not Found value.

See also:

ICachedDatasetLookup