Jacek Laskowski 57 Posted March 13, 2020 How to clear structure of TFDMemTable? Not only data like in EmptyDataset() method, but fields, indexes, filters, etc. too. Is possible? Share this post Link to post
Kryvich 163 Posted March 13, 2020 mt.Free; mt := TFDMemTable.Create(...); Share this post Link to post
Jacek Laskowski 57 Posted March 13, 2020 This is not a very sophisticated solution 🙂 I was hoping for something better. But... thanks. Share this post Link to post
Lars Fosdal 1765 Posted March 13, 2020 There are various ClearXxx methods for TFDMemTable, but it is not obvious which one(s) to call, or in which order, and if they actually reset the whole thing. The above suggestions, on the other hand, are solid. Share this post Link to post
Wloochacz 2 Posted April 2, 2020 Hello Jaca! :) There is no simple solution for that. However, I would suggest basing your own solution on the CopyDataSet code. Note that if you specify the coStructure parameter in the options of CopyDataSet method, you will get what you want. Almost ;-) Share this post Link to post
teri 0 Posted October 5, 2023 Hello - I'm having same/similar issue when I try to reuse a TFDMemTable to load varying column count csv files. I read in the csv's header, construct the table fields then create the table. The second time it's run, I get a duplicate FieldDef error. fdmColumns is a TFDMemTable containing the list of column headings. fdmColumnValues is the TFDMemTable I want to load the contents of the csv file into. What am I missing? Teri procedure DefineTable; begin fdmColumns.First; fdmColumnValues.Free; fdmColumnValues := TFDMemTable.Create(self); while not fdmColumns.eof do begin with fdmColumnValues.FieldDefs.AddFieldDef do begin Name := fdmColumns['ColumnName']; DataType := ftString; end; fdmColumns.Next; end; fdmColumnValues.CreateDataSet; dsColumnValues.DataSet := fdmColumnValues; end; Share this post Link to post
Hans J. Ellingsgaard 21 Posted October 7, 2023 When you are defining all the fields in runtime, why not also create the table in runtime? Share this post Link to post
Jeff Overcash 2 Posted October 9, 2023 Clear not only the Fields property but the FieldDefs too. Do this while the dataset is closed. Then you can rebuild your new fielddefs. if FDMemTable1.Active then begin FDMemTable1.Close; FDMemTable1.Fields.Clear; FDMemTable1.FieldDefs.Clear; end; Now it is ready for you to define the new columns. Index etc done the same way, just clear their definitions. Don't forget there are both an Indexes and an IndexDef, both should be cleared. Filter you would just assign the empty string. 1 Share this post Link to post
teri 0 Posted October 10, 2023 Thanks for the responses. I was actually clearing the dataset fdmColumnValues correctly, by clearing Fields and FieldDefs, but I had neglected to empty the fdmColumns dataset which I was using to define the field names. Thus, I was getting a duplicate field error. DOH! Teri Share this post Link to post
adyble 0 Posted December 6, 2023 Hi I'm having exactly the same problem - I've simplified my process for the purpose of this post - QryChart.Sql.Text := 'SELECT CHARTSERIES, TOTAL, CHARTDATE FROM ORDERS' ; QryChart.Open ; memChartData.Close ; memChartData.Indexes.Clear; memChartData.IndexDefs.Clear; memChartData.Fields.Clear; memChartData.FieldDefs.Clear; memChartData.CopyDataSet(dmData.QryChart, [coStructure, coRestart, coAppend]); So far, no problem. Then QryChart.Close ; QryChart.Sql.Text := 'SELECT CHARTSERIES, TOTAL FROM ORDERS' ; QryChart.Open ; memChartData.Close ; memChartData.Indexes.Clear; memChartData.IndexDefs.Clear; memChartData.Fields.Clear; memChartData.FieldDefs.Clear; memChartData.CopyDataSet(dmData.QryChart, [coStructure, coRestart, coAppend]); It fails on CopyDataSet with the message CHARTDATE object not found, so it clearly hasn't removed that field form the defs. Thanks for any advice. Andy Share this post Link to post