Include the Registry.hpp file:
#include <Registry.hpp>
Then, in any function, you can write the following to read the value:
String __fastcall ReadRegistryString(const String &key, const String &name, const String &def) { TRegistry *reg = new TRegistry(); String result; try { reg->RootKey = HKEY_CURRENT_USER; if (reg->OpenKeyReadOnly(key)) { result = reg->ReadString(name, def); reg->CloseKey(); } } __finally { delete reg; } return result; }
Therefore, reading the value should be as simple as:
ShowMessage(ReadRegistryString("Options", "Last Directory", "none"));
You can use the following to record the value:
void __fastcall WriteRegistryString(const String &key, const String &name, const String &value) { TRegistry *reg = new TRegistry(); try { reg->RootKey = HKEY_CURRENT_USER; if (reg->OpenKey(key, true)) { reg->WriteString(name, value); reg->CloseKey(); } } __finally { delete reg; } }
There has to be self-updating, remembering the attempt ... is finally really useful when using the VCL class TRegistry.
Edit
I heard that .ini files are stored in the registry on Windows, so if you need the speed advantage of ini files, you should call them something else - for example .cfg
This is what I heard from a reliable source, I have not tested it myself.