Using Delphi 10.2.3, I dropped in a form a Firedac TFDMemTable
component which was I used Field Editor to define 5 fields, one of those fields is a Lookup Field (FieldKind = fkLookup
) .
I created a code to scan all fields of the MemSource
MemTable to add those fields in a MemDestination
Memtable.
I had a problem in scan the MemSource.FieldDefs
because its total number of fields did not consider the Lookup one ! See the code :
procedure TFormA.BTCopyFieldsClick(Sender: TObject);
var
i : integer;
begin
for I := 0 to MemSource.FieldDefs.Count-1 do
begin
if (memSource.Fields.Fields[i].FieldKind = FkData) then
memDestination.FieldDefs.Add (
memSource.FieldDefs.Items[i].DisplayName,
memSource.FieldDefs.Items[i].DataType,
memSource.FieldDefs.Items[i].Size,
memSource.FieldDefs.Items[i].Required
)
Else
ShowMessage( GetEnumName(TypeInfo(TFieldKind),
Integer(memSource.FieldDefs.Items[i].Datatype)
);
memDestination.CreateDataSet;
memDestination.CopyDataSet(memSource,[coRestart, coAppend]);
end;
end;
I realized that memSource.FieldDefs.Count
had 4 fields only, it missed the 5th one which was a lookup type .
However memSource.Fields.Count
accounts for 5 fields, that is correct.
The questions are :
Is lookup field defined at design time considered in
FieldDefs
?
(if it is not considered, so WHY ?)Why
memSource.FieldDefs.Count
is different frommemSource.Fields.Count
? (i.e. I have more fields in the memtable than in its definition )
Am I doing somethinf wrong in the above code ? What ?
Thanks in advance !!