views:

272

answers:

1

I'm using TClientDataset.CloneCursor to implement different views of the same data. I have a master dataset, and several clones, each of which contains a different subset of the master dataset's fields. But when I try to display data from the clones, they come up empty. The master dataset is populated with data correctly, and the clone datasets' CloneSource property is pointing to the correct dataset, but if I put two grids side-by-side, one showing the master and the other linked to a clone view, the clone view one will be blank.

Any idea what can cause this?

+2  A: 

OK, since you don't have any code, I'll write some for you. This sounds like what you are talking about doing, and it works on my machine. So now you tell me what you are doing differently. Put two each of a TClientDataSet, TDataSource, TDBGrid down. Wire them up and name them correctly:

var
  idField: TFieldDef;
  stringField: TFieldDef;
begin
  idField := ds1.FieldDefs.AddFieldDef;
  idField.DataType := ftInteger;
  idField.Name := 'id';

  stringField := ds1.FieldDefs.AddFieldDef;
  stringField.DataType := ftString;
  stringField.Size := 10;
  stringField.Name := 'name';

  ds1.CreateDataSet;
  ds1.InsertRecord([1, 'Jim McKeeth']);
  ds1.InsertRecord([2, 'Mason Wheeler']);
  ds1.InsertRecord([3, 'Jeff Atwood']);

  ds2.CloneCursor(ds1, true);
  ds2.Filter := 'id=1';
  ds2.Filtered := True;
end;
Jim McKeeth
I'm defining the fields at design-time, and they have to be defined for both datasets, not just the one. And I'm cloning the cursor before adding the data. And the second dataset doesn't even have a filter yet. (It's going to, but I left it off to eliminate that as a source of trouble.)
Mason Wheeler
I didn't need to define fields on the second dataset, and it behaves the same if the fields are defined at design or run time. I would suggest removing the fields from the second dataset and seeing if that fixes the problem.
Jim McKeeth