Reputation: 81
I am trying to replace Delphi ClientDatasets That worked fine but just very slow on large data with Firedac MemoryTables I create a FireDac Memory Table in a data module and populate it from a form. In the Form I check the record count of the Memory Table and it contains records. I then close the memory table and reopen it but it returns an empty table after opening.
Dataform.mtDebTran.FileName := CdsDir + '/DebTran.Fds';
DataForm.mtDebTran.CreateDataSet
DataForm.mtDebTran.CreateDataSet;
DataForm.mtDebTran.Open;
DataForm.BuildDebTranTemp1(P1,P2,P3,P4,True,True);
DataForm.mtDebTran.SaveToFile(CdsDir + '/DebTran',sfBinary);
ShowMessage(IntToStr(DataForm.mtDebTran.RecordCount));
DataForm.mtDebTran.Close;
DataForm.mtDebTran.Open;
ShowMessage(IntToStr(DataForm.mtDebTran.RecordCount));`
Upvotes: 1
Views: 1798
Reputation: 30715
Is that your real code, and is it complete? You're calling CreateDataSet twice in succession
DataForm.mtDebTran.CreateDataSet
DataForm.mtDebTran.CreateDataSet;
for no apparent reason, but anyway if your mtDebTran dataset was supposed to contain data before the first call to CreateDataSet, that call will empty it, because that's what it's supposed to do.
You say "but it returns an empty table after opening." and presumably you intended to ask why that is the case. Well, in
DataForm.mtDebTran.Close;
DataForm.mtDebTran.Open;
after the call to .Close, mtDebTran will contain no data, because a DataSet discards its data when .Close it called and calling .Open will not restore it - the dataset will still be empty. To get the data, you need to reload the data from the file created in .SaveToFile. Or not call .Close in the first place, of course.
Btw, in your code, mtDebTran is a member of DataForm, but in the text of your q. you say "I create a FireDac Memory Table in a data module" so presumably the FireDac table is a different one from mtDebTran?
Also btw, if mtDebTran is actually a TClientDataSet, then mentioning FireDac tables in your q and its title is irrelevant and misleading.
Upvotes: 5