안녕하세요.
C++Builder 6을 가지고 프로그래밍을 시작한 사람입니다.
1280p의 개발자 안내서를 다운로드 받아 소스를 입력하며
공부하고 있는데요.
왜 안될까요!!
1. 폼의 생성자 및 OnClose 이벤트 핸들러의 쓰기 값에 있는 ini 파일로부터 구성 정보를 읽는 예제입니다. (실행)
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TIniFile *ini;
ini = new TIniFile( ChangeFileExt ( Application->ExeName, ".INI" ) );
Top = ini->ReadInteger( "Form", "Top", 100 );
Left = ini->ReadInteger( "Form", "Left", 100 );
Caption = ini->ReadString( "Form", "Caption", Default Caption" );
ini->ReadBool( "Form", "InitMax", false ) ?
WindowState = wsMaximized : WindowState = wsNormal;
delete ini;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
TIniFile *ini;
ini = new TIniFile(ChangeFileExt( Appllication->ExeName, ".INI" ) );
ini->WriteInteger( "Form", "Top", Top );
ini->WriteInteger( "Form", 'Left", Left );
ini->WriteString( "Form", "Caption", Caption );
ini->WriteBool( "Form", "InitMax", WindowState == wsMaximized );
delete ini;
}
이렇게 작성하고 Alt + F9 눌렀는데 왜 에러가 날까요. (다른 것도 실행)
2. TRegistryIniFile 사용
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
AnsiString GetRegitryValue(AnsiString KeyName)
{
AnsiString S;
TRegistry *Registry = new TRegistry(KEY_READ);
try
{
Registry->Rootkey = HKEY_LOCAL_MACHINE;
Registry->OpenKey(KeyName, false);
s = Registry->ReadString("VALUE1");
}
__finally
{
delete Registry;
}
return S;
}
이것도 역시 에러가 납니다. 개발자 안내서를 가지고 공부하려고 했는데 뜻대로 안되네요.
에러가 나는 이유와 해결 방법을 알려주시면 감사드리겠습니다.
|