Ad
Add Field To FDMemTable In Delphi
I am coding something with DBGrid and there is not enough data witch i cen get with FDQuery. I would like custom data beside "FDQuery" data. I found component that should be able to do this and it is called FDMemTable. I can get data from FDQuery to FDMemTable, but I cant add a new field where I can put different data. So my question is how to propper connect the data with FDQuery and add extra column in FDMemTable.
procedure TWorkflowDM.Temp;
var
Error: string;
Temp: string;
begin
try
FDQuery1.Open;
FDQuery1.FetchAll;
FDMemTable1.Data:= FDQuery1.Data;
FDMemTable1.FieldDefs.Add('Test', ftString, 20, False); <-ERROR (Error 'FDMemTable1: Field ''Test'' not found')
FDMemTable1.Open;
FDMemTable1.First;
while not FDMemTable1.Eof do
begin
Temp:= FDMemTable1.FieldByName('Test').AsString;
FDMemTable1.Next;
end;
except
on E: Exception do
Error:= E.Message;
end;
end;
Ad
Answer
We copy the field definitions from the source DataSet and append the additional fields. Then we call CreateDataset
or optionally set Active to true. This creates all the necessary fields and opens the FDMemTable
. Then we populate it by CopyDataset method. This code works:
procedure TWorkflowDM.Temp;
var
Error: string;
Temp: string;
begin
try
FDQuery1.Open;
// FDQuery1.FetchAll;
FDMemTable1.FieldDefs := FDQuery1.FieldDefs;
FDMemTable1.FieldDefs.Add('Test', ftString, 20{, False}); // default parameter
FDMemTable1.CreateDataSet;//or just Open that sets Active to true;
FDMemTable1.CopyDataSet(FDQuery1);
FDMemTable1.First;
while not FDMemTable1.Eof do
begin
Temp := FDMemTable1.FieldByName('Test').AsString;
FDMemTable1.Next;
end;
except
on E: Exception do
Error := E.Message;
end;
end;
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → I can't do a foreign key, constraint error
- → Setting a default value on settings form return null in Octobercms
- → Eloquent Multitable query
- → "Laravel 5.1" add user and project with userId
- → Image does not go in database with file name only tmp name saved?
- → Database backup with custom code in laravel 5 and get the data upto 10 rows from per table in database
- → Trait 'IlluminateFoundationBusDispatchesJobs' not found
- → Setting the maxlength of text in an element that is displayed
- → laravel check between 2 integer from database
- → how to retrieve image from database in laravel 5.1?
- → relationship for database Column type object
- → Carousel in Laravel 4 does not show as expected
Ad