I’m currently trying to create a “Profile Manager” using a TIniFile to store the data, and displaying the data in various components on a form (editboxes and such).
On the form, i’ve got a Combobox. This serves as a way of displaying the “Profile Name” as set by the user.
The data is being stored in the format of 1 profile per inifile section. Each section contains the configuration data for 1 profile including the Profile Name. The profile name key is the same across each section. This is the sort of layout i’ve currently got in the inifile (as an example);
[0]
PROFILE_NAME=Profile 1A
PROFILE_DATA=Profile Data 1A
PROFILE_PASS=Profile Password 1
PROFILE_USER=Profile Username 1
[1]
PROFILE_NAME=Profile 1B
PROFILE_DATA=Profile Data 1B
PROFILE_PASS=Profile Password 1B
PROFILE_USER=Profile Username 1B
What i want to do is load a list of all values with the key “PROFILE_NAME” into a combobox regardless of what section they’re located in. The section names themselves are references to the itemindex in the combobox when that data was added.
From there, i can handle loading the other data into it’s relevant fields, but i’m having a problem figuring out how to load the “PROFILE_NAME” values into the combobox. Any ideas?
For those familiar with the Voice Communication program “Ventrilo”, it features something similar to what i’m trying to achieve with it’s “Server and User Manager”. It’s inifile layout is very similar, and the only difference i can find is that it has a “USER_COUNT” value referencing how many users have been added. Each user has servers assigned to them, rather than the servers being accessible by every user.
Is it possible for me to achieve this?
You have to use
TIniFile.ReadSectionsto get a list of all the section names, and then you can loop through them and read the individualPROFILE_NAMEfrom each of those sections. (I preferTMemIniFile, asTIniFileis based on the WinAPI functions directly and has issues sometimes on network drives when trying to update with new values.TMemIniFilealso works cross-platform when you get toXE2.)I’m creating the
TMemIniFileandTStringListand freeing them, but if you’re using them repeatedly you’ll probably want to create them in your form’sOnCreateand free them inFormCloseinstead; that way you’ll have a list of the section names to match back to the items in theComboBoxwhen you want to access the rest of the items in theOnClickevent to populate the rest of the form.To make it easier to tie back to the items in the
ComboBox, declare a new integer variable (iin my snippet below), and change theforloop to this (make sure you don’t sort theSections– let theComboBoxhandle the sorting!):To get the section name again when the user clicks a combobox item: