Answer the question
In order to leave comments, you need to log in
How to correctly load program settings in Delphi
Hello everyone, actually the question is: how is it more correct / more competent / better to load the program settings? Previously, the whole thing was driven in Splash form. But the matter was limited to a couple of self-written procedures in OnCreate. I saw many different methods on the Internet, but, as you know, a good community in delphists is worth its weight in gold, so many examples are written by people who themselves do not understand whether they wrote the method correctly, so I ask you.
I decided that I would use INI files (yes, I know how good XML is, but I don’t need a hierarchy of settings, and the parser is slower, and I don’t want to mess with the register).
Is it possible to load them once and work throughout the program cycle? Or here, according to the principle, I read it - applied it - closed it? Can you please share how you do it? Not necessarily in Delphi, the algorithm itself is needed, but writing is not a problem. Thank you.
Answer the question
In order to leave comments, you need to log in
If you have a 1GB database in INI, then it's better - read the setting and close the file.
If INI is like everyone else's (a few kilobytes) - then read and keep in memory only those that will be constantly used when working with the program (other variables - kill, freeing up memory).
When you open the configuration window in the program - check the correspondence of the information on the disk (read again the data from INI) and those in memory:
1. missing parameters (from which the memory was freed earlier) - read again from the INI file.
2. if the list of parameters or their properties does not match, inform the user: "The settings file on the disk has been changed. Update the settings with data from the file or use the current ones?"
Do the same when exiting the application and check the integrity of the data structure in the INI file. (let the user know if something is wrong by setting a timer on the default operation)
In Win32, the biggest problem is resources. Each opening of a file consumes memory and a handle for this file. Therefore, everyone reads the settings and immediately closes them. In addition, in case of an accidental crash of the system, such resources can arbitrarily capture such resources and the data in them will be corrupted.
you can store the data however you like. The easiest way is to use a descendant of TStrings. More possibilities gives IniFile. Well, more advanced features are storage in a format similar to a dfm file.
And these are all methods that are already in the structure of Delphi programs and which do not need to attach wheels to get a bicycle.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question