Урок 44 Работа с реестром
May 24, 2007
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <Registry.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if (Key ==VK_RETURN)
{
Form1->Caption = Edit1->Text;
}
}
//---------------------------------------------------------------------------
//Запись в реестр
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TRegistry *RegForm =new TRegistry;
try
{
RegForm->RootKey=HKEY_CURRENT_USER;
RegForm->OpenKey("Software\\MoySoft",true);
RegForm->WriteInteger("POSLeft",Form1->Left);
RegForm->WriteInteger("POSTop",Form1->Top);
RegForm->WriteInteger("POSWidth",Form1->Width);
RegForm->WriteInteger("POSHeight",Form1->Height);
RegForm->WriteString("FCaption",Form1->Caption);
RegForm->WriteString("EText",Edit1->Text);
}
__finally
{
delete RegForm;
}
}
//---------------------------------------------------------------------------
//Чтение из реестра
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TRegistry *RegForm =new TRegistry;
try
{
RegForm->RootKey=HKEY_CURRENT_USER;
RegForm->OpenKey("Software\\MoySoft",true);
Form1->Left = RegForm->ReadInteger("POSLeft");
Form1->Top = RegForm->ReadInteger("POSTop");
Form1->Width = RegForm->ReadInteger("POSWidth");
Form1->Height = RegForm->ReadInteger("POSHeight");
Form1->Caption = RegForm->ReadString("FCaption");
Edit1->Text = RegForm->ReadString("EText");
}
__finally
{
delete RegForm;
}
}
//---------------------------------------------------------------------------
Author of article - Medneem 2007
www.builderhelper.org
builder.helper@rambler.ru