RAD Studio VCL Reference
|
Occurs when the data in a record has changed, either due to field edits or moving the cursor to a new record.
property OnDataChange: TDataChangeEvent;
__property TDataChangeEvent OnDataChange;
Write an OnDataChange event handler to take specific actions when a field in the current record has been edited and the application moves to another field, or when the current record in the associated dataset changes. OnDataChange is especially useful in applications that must synchronize data display in controls that are not data-aware. This event is typically used to make sure the control reflects the current field values in the dataset, because it is triggered by all changes.
Methods that can trigger this event include the Next or Prior methods for the dataset. Data-aware controls notify a data source of a data change when:
Scrolling to a new record.
Modifications to a field's data.
Delphi Examples:
{ This example uses a button to copy the value of a field in the previous record into the corresponding field in the current record. } procedure TForm1.Button1Click(Sender: TObject); var SavePlace: TBookmark; PrevValue: Variant; begin with Customers do begin { get a bookmark so that we can return to the same record } SavePlace := GetBookmark; try { move to prior record} FindPrior; { get the value } PrevValue := Fields[1].Value; {Move back to the bookmark this may not be the next record anymore if something else is changing the dataset asynchronously } GotoBookmark(SavePlace); { Set the value } Edit; Fields[1].Value := PrevValue; { Free the bookmark } finally FreeBookmark(SavePlace); end; end; end; { To ensure that the button is disabled when there is no previous record, the OnDataChange event of the DataSource detects when the user moves to the beginning of file (BOF property becomes true), and disables the button. Detection occurs on scrolling and editing, not selection with the mouse. } procedure TForm1.DS2DataChange(Sender: TObject; Field: TField); begin if Customers.Bof then Button1.Enabled := False else Button1.Enabled := True; end;
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|