I am trying to use the following code to get a list of subkeys in the registry. GetKeyNames takes a TString object. Upon return, the TStringList object has a count of 3 which is the correct count. However, while the TStringList has the proper count, it doesn't seem to have the names. This is probably something simple, but I haven't been able to discover the problem.
TRegistry *pRegistry = new TRegistry(KEY_READ);
pRegistry->RootKey = HKEY_LOCAL_MACHINE;
pRegistry->OpenKeyReadOnly(L"\\SOFTWARE\\Ogre\\Fasthole");
TStringList *subkeyNames = new TStringList();
pRegistry->GetKeyNames(subkeyNames);
UnicodeString ALICE = subkeyNames->Names[0];
ALICE is always NULL.
UPDATE:
The project being modified was originally developed with C++Builder 12.1 Athens. I updated that project to 12.2 by creating a new project and adding all of the original forms to it. I still get the same result. I kept working on it and found the following:
TStringList *subkeys = new TStringList();
pRegistry->GetKeyNames(subkeys);
UnicodeString RALPH = subkeys->Strings[0]; <--- this fails
UnicodeString ALICE = subkeys->Strings[1][1]; <--- this also fails
wchar_t NORTON = subkeys->Strings[0][1]; <--- this works
wchar_t TRIXIE = RALPH[1]; <--- this also worked!!!
If I try to use any of the UnicodeStrings, I get NULL values.
Since I'm working with single character keys, I can work around it, but it's certainly not right.
You need to use the TStringList's Strings[] property instead of its Names[] property:
//UnicodeString ALICE = subkeyNames->Names[0];
UnicodeString ALICE = subkeyNames->Strings[0];
TRegistry::GetKeyNames() returns the key names as-is, not in "name=value" format, which is why the Names[] property is returning a blank string - there is no name for it to return:
When the list of strings for the
TStringsobject includes strings that are name-value pairs, readNamesto access the name part of a string.Namesis the name part of the string atIndex, where 0 is the first string, 1 is the second string, and so on. If the string is not a name-value pair,Namescontains an empty string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With