I use Delphi 10.3. I try to make a memory database, append data to it and find data in it.
I wrote the following code referring other's and it works well.
procedure TForm1.DataAppendFind;
var
_FieldDef: TFieldDef;
_FDDatsRow: TFDDatSRow;
i: Integer;
begin
_FieldDef := FDMemTable1.FieldDefs.AddFieldDef;
_FieldDef.Name := 'field1';
_FieldDef.DataType := ftInteger;
_FieldDef := FDMemTable1.FieldDefs.AddFieldDef;
_FieldDef.Name :='field2';
_FieldDef.DataType := ftString;
_FieldDef.Size := 10;
FDMemTable1.CreateDataSet;
FDMemTable1.Append;
FDMemTable1.FieldValues['field1'] := 1;
FDMemTable1.FieldValues['field2'] := 'one';
FDMemTable1.Append;
FDMemTable1.FieldValues['field1'] := 2;
FDMemTable1.FieldValues['field2'] := 'two';
FDMemTable1.First;
for i := 0 to FDMemTable1.RecordCount - 1 do
begin
_FDDatsRow := FDMemTable1.GetRow;
if _FDDatsRow.Values['field1'] = 2 then
begin
Caption := _FDDatsRow.ValueS['field2'];
end;
FDMemTable1.Next;
end;
end;
I can't understand TFDDatSRow that I tried to search it through Delphi references and google for it. But there is no clear document about that. I can guess it is similar with a row but is not a row because it has a long and complex name which is not just a tROW.
What is TFDDatSRow, why there is no reference about it and where can I get the proper information about that? And lastly is the code above correct?
Yes, your code works correctly. I confess I had not come across TFDDatSRow before your q, but having looked at it, it's pretty obvious what it is for.
FireDAC's dataset components all descend from TDataSet, and therefore comply with its way of modelling dataset operations, which is to say that while a dataset is open, it has a logical cursor which is "over" exactly one record in the dataset and it is that record, the "active" one in Delphi's terms, on which operations like
Edit,Post,FieldByName, etc take place. This works fine but makes some operations impossible, such as working on two records simulataneously, e.g. when you want to exchange values between two different records, because they can't both be the active record of the dataset at the same time.I said it's pretty obvious what TFDDatSRow is for and one thing is to allow exactly that kind of concurrent access to 2 or more records possible.
For example, this code
enables data to be transferred from the second row to the first in a way that wouldn't be possible without TFDDatSRow.
Why isn't it documented? Don't know, ask EMBA.
How did I find out its methods? Simple, I declared a variable
and then typed
and the IDE's code completion popped them up.
Also, selecting
TFDDatSRowand doing Ctrl-Click takes me to its declaration in the FireDac.DatS unit. Looking in there, FireDAC's author obviously hand in mind a lot more than is shown in my example.