PhilPlus 6 Posted November 12, 2022 I typically use TFDQuery connected to a database to use with a TDBGrid. Everything is OK but I would sometimes need to disconnect this TFDQuery while keeping the data in the TDBGrid, just for visualization, with, of course the loss of some functions related to the data update, but it does not pose any problem. It seems to me that it was possible with the old library 'ADODB' : http://etutorials.org/Programming/ma...ed+Recordsets/ Unfortunately I haven't found how to do this with the Firedac components (apart from making a copy in a TFDMemTable but this is a bit cumbersome). Has anyone already implemented this principle? Share this post Link to post
haentschman 92 Posted November 13, 2022 Hi... That's why the components are called "data sensitive". Without a direct connection to the database you have no data.... (unless there is something new ) You have to come up with a separation of data and database. Variant 1: 1. load data with query 2. transfer the data into objects 3. throw away query 4. change data in object 5. save object with SQL (create query, throw away query) ... with this variant one gets along also without data-sensitive components. You can then display an object in the grid as well as a property in the edit. Variant 2: Copy to another dataset: https://docwiki.embarcadero.com/Libraries/Sydney/en/FireDAC.Comp.DataSet.TFDDataSet.CopyDataSet Imho there are other variants.... Share this post Link to post
mjustin 23 Posted November 13, 2022 (edited) A TClientDataSet (together with a TDataSetProvider) can be used. Even when the Connection is closed, the TClientDataSet is still showing all data. This briefcase-model programming style is available since around Delphi 3, where the architecture was branded as MIDAS, later renamed to Datasnap. So basically this is needed: * a TFDQuery * which is connected to a TDatasetProvider, which in turn * is connected to the TClientDataSet. The TFDQuery or its connection may be closed without losing the data in the TClientDataSet Resources: https://docwiki.embarcadero.com/Libraries/Sydney/en/Datasnap.Provider.TDataSetProvider https://docwiki.embarcadero.com/Libraries/Sydney/en/Datasnap.DBClient.TClientDataSet Edited November 13, 2022 by mjustin Share this post Link to post
Fr0sT.Brutal 900 Posted November 14, 2022 18 hours ago, mjustin said: TClientDataSet Or any memory dataset. I believe Firedac has one Share this post Link to post
Anders Melander 1783 Posted November 15, 2022 12 hours ago, Fr0sT.Brutal said: Or any memory dataset. I believe Firedac has one In principle, all FireDAC datasets are memory datasets. TFDMemTable is just a FireDAC dataset with no database connection. FireDAC supports both "offline mode" and cached updates, so there's really no need to use TClientDataSet in this case. However, it sounds as if the OP really just needs to set up the TFDQuery to fetch all data and then close the DB cursor. Something like this: Query.FetchOptions.Mode := fmAll; Query.FetchOptions.AutoClose := True; Share this post Link to post
PhilPlus 6 Posted November 15, 2022 On 11/13/2022 at 9:49 AM, haentschman said: Hi... That's why the components are called "data sensitive". Without a direct connection to the database you have no data.... (unless there is something new ) You have to come up with a separation of data and database. Variant 1: 1. load data with query 2. transfer the data into objects 3. throw away query 4. change data in object 5. save object with SQL (create query, throw away query) ... with this variant one gets along also without data-sensitive components. You can then display an object in the grid as well as a property in the edit. Variant 2: Copy to another dataset: https://docwiki.embarcadero.com/Libraries/Sydney/en/FireDAC.Comp.DataSet.TFDDataSet.CopyDataSet Imho there are other variants.... Thx I yet use these 2 variants (more or less) but I would find a simpler way as FDDataset have all the data in memory. Share this post Link to post
PhilPlus 6 Posted November 15, 2022 On 11/13/2022 at 5:42 PM, mjustin said: A TClientDataSet (together with a TDataSetProvider) can be used. Even when the Connection is closed, the TClientDataSet is still showing all data. This briefcase-model programming style is available since around Delphi 3, where the architecture was branded as MIDAS, later renamed to Datasnap. So basically this is needed: * a TFDQuery * which is connected to a TDatasetProvider, which in turn * is connected to the TClientDataSet. The TFDQuery or its connection may be closed without losing the data in the TClientDataSet Resources: https://docwiki.embarcadero.com/Libraries/Sydney/en/Datasnap.Provider.TDataSetProvider https://docwiki.embarcadero.com/Libraries/Sydney/en/Datasnap.DBClient.TClientDataSet Thx, but TClientDataset seems more complex than my (not very cean) solution : a copy to FDMemeryTable, but it may be more efficient (perf and memory). Share this post Link to post
PhilPlus 6 Posted November 15, 2022 10 hours ago, Anders Melander said: In principle, all FireDAC datasets are memory datasets. TFDMemTable is just a FireDAC dataset with no database connection. FireDAC supports both "offline mode" and cached updates, so there's really no need to use TClientDataSet in this case. However, it sounds as if the OP really just needs to set up the TFDQuery to fetch all data and then close the DB cursor. Something like this: Query.FetchOptions.Mode := fmAll; Query.FetchOptions.AutoClose := True; Ok but even with these options, when the TConnection is closed (FDConnection1.Connected := false) all the data are lost. So how to use the "offlien mode" ? Share this post Link to post
Anders Melander 1783 Posted November 15, 2022 20 minutes ago, PhilPlus said: So how to use the "offlien mode" ? Read the documentation. Search for FireDAC offline 2 Share this post Link to post
PhilPlus 6 Posted November 15, 2022 37 minutes ago, Anders Melander said: Read the documentation. Search for FireDAC offline Excellent Anders, excellent ! I didn't know this, first tests show that it was the exact simple solution I was looking for. The code is FDConnection1.Offline; Share this post Link to post