Skip to main content

TcxDBDataController.BeginLocate Method

Prevents the data controller from reloading data when you move the cursor within a dataset via the Locate, First and Last methods.

Declaration

procedure BeginLocate;

Remarks

The BeginLocate and EndLocate methods work together. Use these methods to prevent the data controller from reloading data when moving the cursor within the dataset with the help of TDataSet methods (Locate, First and Last).

The Locate method lets you search the dataset for a record meeting the specified criteria. This method (as well as First and Last) changes the active dataset record and implicitly sends a change notification to the data controller. The same notification is sent when you use TDataSet methods/properties to modify field values and insert and delete records.

On receiving the change notification, the data controller reloads records from the dataset, since it does not exactly know what has caused the notification.

When you just want to make another record active and do not want to change field values in the dataset, data reloading is unnecessary. Also, this operation can require significant time for huge datasets. In this case, you can consider using the BeginLocate and EndLocate methods to enclose call(s) to the Locate, First or Last methods. After BeginLocate is called, but before EndLocate is called, the data controller assumes that you will use dataset methods only to locate specific records and that you will not change them. On receiving the change notification, the data controller will not reload data. However, it will reflect the new position of the active record.

BeginLocate does not disable the events related to changing the active record. For instance, in ExpressQuantumGrid, the view’s OnFocusedRecordChanged event still occurs when changing the active dataset record.

After EndLocate is called, reloading dataset data does not occur automatically. EndLocate enables default data reloading each time a change notification is received.

Note that every BeginLocate call must correspond to an EndLocate call. To ensure that EndLocate is always called for BeginLocate even if an exception occurs, use a try…finally block.

If you need to iterate through records to change them, you should use the dataset’s DisableControls and EnableControls methods instead to prevent excessive updates of the data controller.

See Also