I would like my application to remember which selected row in the database table was used (selected) before the application got closed and then load it (have it selected) the next time the application starts.The table has only 4 records and is read only so I dont have to worry if someone tries to change anything. Right now I use :
procedure TForm3.ClientDataSet1AfterOpen(DataSet: TDataSet);
begin
Clientdataset1.DisableControls;
try
cxGrid1DBTableView1.DataController.KeyFieldNames := 'ID';
cxGrid1DBTableView1.DataController.LocateByKey('4');
finally
Clientdataset1.EnableControls;
end;
end;
But this is hardcoded. I want it flexible. How can I save these settings to an ini file located in the application.exe folder and load them when the application starts ? So ,for example,if key was '3' (when the app. exited) I load it the next time.
Use the
TDataSet.OnAfterOpen
andTDataSet.OnBeforeClose
events to load and save the desired valuesThis is a very simple and straight forward sample and you should not implement this in real applications.
In real applications you will delegate this to a singleton that takes care of reading and writing such application values
and gives you a very smart solution