'ini'에 해당되는 글 1건

testdb.ini 화일에 다음과 같이..쓴다...

[DATABASE]
SERVERNAME=210.222.XXX.XXX
DATABASENAME=D:delphidatatestdb.gdb
USERNAME=sysdba
PASSWORD=masterkey
----------------------------------------------

다음은 델파이 소스에서 ini 읽어오는 것...
일단 uses절에 IniFiles을 추가한후.

원하는 이벤트나 함수를 만들어서 다음과 같이 해준다.

procedure TForm1.FormCreate(Sender: TObject);
var
Ini: TIniFile;
begin
Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.INI' ) );
try
   SERVERNAME := Ini.ReadString( 'DATABASE', 'SERVERNAME', '' );
   DATABASENAME := Ini.ReadString( 'DATABASE', 'DATABASENAME', '' );
   USERNAME := Ini.ReadString( 'DATABASE', 'USERNAME', '' );
   PASSWORD := Ini.ReadString( 'DATABASE', 'PASSWORD', '' );
finally
   Ini.Free;
end;
end;


참고 2: ini을 처음 시작할때 만들고 저장버튼 누를때 update하고....등등...
config.ini 문서는 아래...

[CRMV]
USERID_CRMV=crmusr7
PASSWORD_CRMV=dbm2002
[VALEX]
USERID_VALEX=crmusr8
PASSWORD_VALEX=dbm2003

procedure TFrmIDPASS.Btn_SaveClick(Sender: TObject);
var
Ini: TiniFile;
ReadIniFileName : String;
begin
//  Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.ini' ) );
ReadIniFileName := 'c:tempformatconfig.ini';

Ini := TIniFile.Create( ReadIniFileName );
try
   ini.WriteString( 'CRMV', 'USERID_CRMV', Edt_CRMVID.Text );
   ini.WriteString( 'CRMV', 'PASSWORD_CRMV', Edt_CRMVPASS.text );
   ini.WriteString( 'VALEX', 'USERID_VALEX', Edt_VALID.text );
   ini.WriteString( 'VALEX', 'PASSWORD_VALEX', Edt_VALPASS.text );
finally
   ini.Free;
end;

ShowMessage('저장하였습니다.');
end;

procedure TFrmIDPASS.ReadINI;
var
Ini: TiniFile;
begin
//  Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.ini' ) );
Ini := TIniFile.Create( 'c:tempformatconfig.ini' );
try
   USERID_CRMV    := ini.ReadString( 'CRMV', 'USERID_CRMV', '' );
   PASSWORD_CRMV  := ini.ReadString( 'CRMV', 'PASSWORD_CRMV', '' );
   USERID_VALEX   := ini.ReadString( 'VALEX', 'USERID_VALEX', '' );
   PASSWORD_VALEX := ini.ReadString( 'VALEX', 'PASSWORD_VALEX', '' );
finally
   ini.Free;
end;
end;

//프로그램 최초 한번만 실행함..ini 파일있음 다음부터 실행하지 않음
procedure TFrmIDPASS.WriteINI;
var
Ini: TiniFile;
WriteIniFileName : String;
begin
//  Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.ini' ) );
WriteIniFileName := 'c:tempformatconfig.ini';

if Not FileExists(WriteIniFileName) then
begin
   Ini := TIniFile.Create( WriteIniFileName );
   try
     ini.WriteString( 'CRMV', 'USERID_CRMV', 'crmusr7' );
     ini.WriteString( 'CRMV', 'PASSWORD_CRMV', 'dbm2002' );
     ini.WriteString( 'VALEX', 'USERID_VALEX', 'crmusr8' );
     ini.WriteString( 'VALEX', 'PASSWORD_VALEX', 'dbm2003' );
   finally
     ini.Free;
   end;
end;
end;

procedure TFrmIDPASS.FormCreate(Sender: TObject);
var
IniFileName : String;
begin
IniFileName := 'c:tempformatconfig.ini';
if FileExists(IniFileName) then
begin
   ReadINI;
   Edt_VALID.Text := USERID_VALEX;
   Edt_VALPASS.Text := PASSWORD_VALEX;
   Edt_CRMVID.Text := USERID_CRMV;
   Edt_CRMVPASS.Text := PASSWORD_CRMV;
end;
end;
Posted by csbuilder
TAG