RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomClientDataSet.CloneCursor Method

Shares the data belonging to another client dataset.

Pascal
procedure CloneCursor(Source: TCustomClientDataSet; Reset: Boolean; KeepSettings: Boolean = False); virtual;
C++
virtual __fastcall CloneCursor(TCustomClientDataSet Source, Boolean Reset, Boolean KeepSettings = False);

Call CloneCursor to share the data belonging to another client dataset. Source indicates another client dataset whose data is to be shared.  

Reset and KeepSettings determine how to set the values of the following properties and events: 

Filter, Filtered, FilterOptions, and OnFilterRecord 

IndexName 

MasterSource and MasterFields 

ReadOnly 

RemoteServer and ProviderName 

If Reset and KeepSettings are both false, the values of the properties listed above are all set to match the source dataset. 

If Reset is true, the properties listed above are all cleared. 

If Reset is false and KeepSettings is true, the properties listed above are not changed. In this case, the application must ensure that existing indexes, providers, and so on are compatible with the cloned data. 

After calling CloneCursor, the data for the client dataset is the same as the data for Source. Edits performed by either client dataset are reflected in the data of both datasets.

Note: Because cloned cursors are shared, changing properties that affect the cursor affect both datasets. For example, setting the ReadOnly property of either dataset will make both datasets read-only.
 

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) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!