RAD Studio VCL Reference
|
Occurs before the client dataset fetches a data packet from the provider.
property BeforeGetRecords: TRemoteEvent;
__property TRemoteEvent BeforeGetRecords;
Write a BeforeGetRecords event handler to send custom information to the client dataset's provider. BeforeGetRecords is part of the mechanism by which a client dataset and a provider communicate information about data fetching. When working with a provider on a stateless application server, this mechanism allows the client dataset and the provider to communicate persistent state information.
When the client dataset fetches data from the application server, the following events occur:
1.The client dataset receives a BeforeGetRecords event, where it can encode custom information into an OleVariant that is passed to the provider as the OwnerData parameter.
2.The provider receives a BeforeGetRecords event, where it can respond to or change that information before it creates a data packet.
3.The provider generates the data packet.
4.The provider receives an AfterGetRecords event, where it can encode custom information into its OwnerData parameter or respond to information from the BeforeGetRecords event handler.
5.The client dataset receives an AfterGetRecords event, where it can respond to the custom information returned by the provider's AfterGetRecords event handler.
Delphi Examples:
{ This example shows how to use the BeforeGetRecords event handler (a TRemoteEventType value) to send the provider information it needs for incremental data fetching. Before fetching the next data packet, the client dataset packages up the key value of the last record so that the provider knows where to begin the next data packet. It also sends some application-specific information, which is stored in Memo1. This method is used to pass the sql statement and the value of the first field for the last record to the server so that the server can return the correct records. The complete project using this code example is in Demos/DelphiWin32/VCLWin32/MIDAS/Pooler. } procedure TForm1.ClientDataSet1BeforeGetRecords(Sender: TObject; var OwnerData: OleVariant); var LastValue: OleVariant; CDSClone: TClientDataSet; begin if ClientDataSet1.Active then begin CDSClone := TClientDataSet.Create(Form1); try CDSClone.CloneCursor(ClientDataSet1, True); { turn off FetchOnDemand so that the clone only fetches the last LOCAL record } CDSClone.FetchOnDemand := False; CDSClone.Last; LastValue := CDSClone.Fields[0].AsString; CDSClone.Close; finally CDSClone.Free; end; end else LastValue := NULL; OwnerData := VarArrayOf([Memo1.Lines.Text, LastValue]); end; procedure TForm1.Button2Click(Sender: TObject); begin ClientDataSet1.PacketRecords := StrToInt(Edit1.Text); ClientDataSet1.GetNextPacket; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|