0

I see having the ability to read record values from a TDataSet descendant without having to move the cursor is a big improvement for people working with database applications.

I have searched long and hard on this topic but the closest I can find is in XE7 TFDMemTable where you can read field values with statements like this:

FirstName := fdsPeople.Table.Rows.ItemsI[i].GetValues('FirstName', True);

where

  1. fdsPeople = instance of TFDMemTable
  2. i = an integer referring to the record index
  3. FirstName is a string variable

Is there already a way to achieve this with a TDataSet that I am not aware of? If not, how can we request for this feature ?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Loc Nguyen
  • 21
  • 3
  • 2
    This only works with an In-Memory-Table where the whole table is in memory (hence the name). Other TDataSets may have some rows in memory for caching (and they will most likely change), but you will rarely have the whole table available. But why do you think that not moving the cursor is a big improvement? – Uwe Raabe Mar 16 '15 at 23:37
  • 1
    Do you actually need this for a generic TDataSet decendant or for a TClientDataSet? In the latter case you can use CloneCursor() to create a cloned TClientDataSet that you can jump through. – Jan Doggen Mar 17 '15 at 08:28

2 Answers2

2

Assuming that you mean you don't want the user to see that you are actually moving the cursor you can do something like this:

var
  BM: TBookmark;
begin
  BM := Dataset.GetBookmark;
  Dataset.DisableControls;
  try
    // Simulate moving the cursor around, reading data etc.
    Dataset.Last;
    Dataset.First;
    Dataset.GotoBookmark(BM)
  finally
    Dataset.EnableControls;
  end;
end;

This assumes you have a bi-directional dataset of course.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Larsdk
  • 705
  • 6
  • 10
  • This seems too many issues to consider (bookmark, disablecontrols, freebookmark, enablecontrols). I really feel Embarcadero should do something at the TDataSet level. – Loc Nguyen Mar 20 '15 at 00:12
2

You can clone cursor from your dataset to other datasets, if your dataset descendant supports this feature ofcourse. (AnyDAC - TADMemTable or FireDAC - TFDMemTable , and TClientDataset support this feature).

It means that datasets can share data, but they have a different cursors! (you can walk by one dataset without disturbing other dataset recNo)

example:

procedure MyCloneCursor(ASourceDS, ADestDS: TFDMemTable)
begin
 ADestDS.FieldDefs.Assign(ASourceDS.FieldDefs);
 ADestDS.CreateDataset;

 ADestDS.CloneCursor(ASourceDS, false {Reset}, false {KeepSettings});
end;

Be aware that KeepSettings refers to datasets that cloned cursor. KeepSettings, if true, indicates that the dataset that cloned cursor will keep it's settings, and if it is false will take settings from the dataset from which cursor was cloned.

If you want to clone filter, indexes, master source, the master fields, read-only status of the source dataset ... then call CloneCursor as follows

CloneCursor(SourceDataset, False, False);

For extensive documentation on this, read Cary Jensen's Cloning ClientDataSet Cursors

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144