views:

80

answers:

3

How to get the sub-key name (eg. Stk Group\ BISCUIT) from registry?

+4  A: 

Are you looking for TRegistry.GetKeyNames(Strings: TStrings);

From help: Returns a string list containing the names of all subkeys belonging to the current key.

Michał Niklas
+4  A: 

use Tregistry's GetKeyNames

http://docwiki.embarcadero.com/VCL/en/Registry.TRegistry.GetKeyNames

glob
+2  A: 
function GetRegSubTree( MainKey : LongInt; var aList : TStringList; aKey :
string ) : Boolean;
var
  hRoot          : HKEY;
  lItem          : LongInt;
  hError         : LongInt;
  szKey,pData          : PChar;
  aString        : String;

begin
   GetRegSubTree:=false;
   if aList=Nil then exit;
{create pointers for the API}
  szKey := StrAlloc( Length( aKey ) + 1 );
  StrPCopy( szKey, aKey );
  lItem := 0;
  pData := StrAlloc( 1024 );

  hError := RegOpenKey( MainKey, szKey, hRoot );
  if hError = ERROR_SUCCESS then
  begin
     while (hError = ERROR_SUCCESS) do
     begin
        hError := RegEnumKey( hRoot, lItem, pData, 1024 );
        if (hError = ERROR_SUCCESS) then
        begin
           GetRegSubTree:=true;
           aList.Add( StrPas( pData ));
           Inc(lItem);
        end;
     end;
     RegCloseKey( hRoot );
  end;
  StrDispose( szKey );
  StrDispose( pData );
end;
XBasic3000
Why are you using the API's when there is a perfectly good and easier to use wrapper class for them (TRegistry)?
Marjan Venema
@Marjan Venema, only if you want your executable size as small as possible
DonnVall
+1 DonnVall. for me, i use the most native/simpliest way to reduce size.
XBasic3000
@DonnVall, @XBasic3000: oh, ok, if size is important I guess I'd do the same. As I am not faced with such constraints I tend to go for understandability, maintainability, ease of use, expressiveness, that sort of thing :-)
Marjan Venema
@Marjan: Lol! I should've said, "On rare occassion when size does matter...". So far I only met two or three projects that specifically ask that requirement (small size). Other than that, of course I will stick with TRegistry.
DonnVall