🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #6869

Re: TRegistry question

#6869
From: Mark Guerrieri
Date: Fri, 08 Apr 2005 18:38
87 lines
3094 bytes
> I'd really
> appreciate a short sample code which does only
> the stuff I mentioned. Thank you.
>

#include <Registry.hpp>

void __fastcall TFrom1::CreateKeys()
{
  TRegistry* registry = new TRegistry;
  try
  {
    registry->RootKey = HKEY_LOCAL_MACHINE;
    registry->Access = KEY_ALL_ACCESS;

    AnsiString cKey = "\\Software\\BLA";

    for(int i=1; i<=2; i++)
    {
      AnsiString cSubKey = cKey + "\\BLA_" + IntToStr(i);

      if(!registry->OpenKey(cSubKey,  true))
        throw Exception("Cannot open/create key " + cSubKey);

      registry->WriteInteger("Value1", 1);
      registry->WriteInteger("Value2", 2);

      for(int j=1; j<=2; j++)
      {
        AnsiString cSubKey2 = cSubKey + "\\BLA_" + IntToStr(i) + "+" +
IntToStr(j);
        if(!registry->OpenKey(cSubKey2,  true))
          throw Exception("Cannot open/create key " + cSubKey2);
        registry->WriteInteger("Value1", 1);
        registry->WriteInteger("Value2", 2);
      }
    }
  }
  __finally
  {
    delete registry;
  }
}

void __fastcall TFrom1::ReadKeys()
{
  TRegistry* registry = new TRegistry;
  try
  {
    registry->RootKey = HKEY_LOCAL_MACHINE;
    registry->Access = KEY_READ;

    AnsiString cKey = "\\Software\\BLA";

    for(int i=1; i<=2; i++)
    {
      AnsiString cSubKey = cKey + "\\BLA_" + IntToStr(i);

      if(!registry->OpenKey(cSubKey,  false))
        throw Exception("Cannot open key " + cSubKey);

      if(registry->ValueExists("Value1"))
        int nValue1 = registry->ReadInteger("Value1");
      if(registry->ValueExists("Value2"))
        int nValue2 = registry->ReadInteger("Value2");

      for(int j=1; j<=2; j++)
      {
        AnsiString cSubKey2 = cSubKey + "\\BLA_" + IntToStr(i) + "+" +
IntToStr(j);
        if(!registry->OpenKey(cSubKey2,  true))
          throw Exception("Cannot open/create key " + cSubKey2);

        if(registry->ValueExists("Value1"))
          int nSubValue1 = registry->ReadInteger("Value1");
        if(registry->ValueExists("Value2"))
          int nSubValue2 = registry->ReadInteger("Value2");
      }
    }
  }
  __finally
  {
    delete registry;
  }
}

Mark
Technical Details
Message-ID: <4256cf97$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4256c523@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,da0d020c56fac00
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Mark Guerrieri" <mguerrieri@nospam_cmsgrp.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4256c523@newsgroups.borland.com>
Subject: Re: TRegistry question
Date: Fri, 8 Apr 2005 14:38:18 -0400
Lines: 89
Organization: Creative Marketing Strategies
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 209.50.174.82
Message-ID: <4256cf97$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1112985495 209.50.174.82 (8 Apr 2005 11:38:15 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail