I have function that should return FDDataset from FDQuery, but I can't copy dataset to Result, or to another FDDataset. This is my main Code:
procedure TForm1.Button1Click(Sender: TObject);
var: Fix: TFDDataSet;
begin
Fix.CreateDataSet;
Fix.CopyDataSet(getFix(1));
end;
and function in another Unit:
function getFix(id: Integer): TFDDataSet;
begin
FDQuery.SQL.Clear;
FDQuery.SQL.ADD('SELECT ....');
...
FDQuery.SQL.Open;
Result.CreateDataSet;
Result.CopyDataSet(FDQuery.Fields.DataSet);
end;
I get error: "Access violation....".
How can I Copy FDQuery results to another TFDDataSet? Or Should I use TClientDataSet? Is there equivalent in FireDac to TClientDataSet?
There are a couple of errors in your code that need to be corrected.
First, it appears that
TFDDataSetis an abstract class (at least parts of it are), even though that's not indicated in the documentation as far as I can tell. This means that you're not able to create and use it as you're wanting. (The source for FireDAC isn't included with the Professional SKUs of Delphi, so I can't look there to confirm.)You can use
TFDMemTableinstead, which works if you create and use it properly. When a function'sResultis an object instance, you have to firstCreatethat object instance before you can use it:BTW, you should probably change the name of your function to remind you that you're also responsible for freeing that dataset after you use it to avoid memory leaks. The proper use, then, would be: