RAD Studio VCL Reference
|
Occurs after an application completes opening a dataset and before any data access occurs.
property AfterOpen: TDataSetNotifyEvent;
__property TDataSetNotifyEvent AfterOpen;
Write an AfterOpen event handler to take specific action immediately after an application opens the dataset. AfterOpen is called after the dataset establishes access to its data and the dataset is put into dsBrowse state. For example, an AfterOpen event handler might check an ini file to determine the last record touched in the dataset the previous time the application ran, and position the dataset at that record.
Delphi Examples:
{ This example adds an entry to a memo with a message when an AfterOpen event or an AfterClose event occurs. Populate the ClientDataSet events with CheckButtonActive. } procedure TForm1.CheckButtonActive(DataSet: TDataSet); begin if (Button1.Enabled) then Memo2.Lines.Add('Now that the dataset is open, record information is available.') else Memo2.Lines.Add('Now that the dataset is closed, record information is not available.'); Button1.Enabled := not ClientDataSet1.Active; Button2.Enabled := ClientDataSet1.Active; Button3.Enabled := ClientDataSet1.Active; end;
{ The following code fragment illustrates how DataSets and DataSetCount can be used to ensure that an action is taken for every open dataset. Assign CheckButtonActive as the AfterClose and AfterOpen event handlers for TClientDataSet1. } procedure TForm1.Button1Click(Sender: TObject); var I: Integer; begin if not RemoteServer1.Connected then RemoteServer1.Connected := True; ClientDataSet1.Close; with RemoteServer1 do begin for I := 0 to DataSetCount - 1 do DataSets[I].EnableControls; end; ClientDataSet1.Open; end; procedure TForm1.Button3Click(Sender: TObject); var I: Integer; begin ClientDataSet1.Close; RemoteServer1.Connected := False; with RemoteServer1 do begin for I := 0 to DataSetCount - 1 do DataSets[I].DisableControls; end; end; procedure TForm1.CheckButtonActive(DataSet: TDataSet); begin Button1.Enabled := not ClientDataSet1.Active; Button2.Enabled := ClientDataSet1.Active; Button3.Enabled := ClientDataSet1.Active; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|