Sabtu, 28 April 2012

Save *.ini Delphi

         Beberapa hari yang lalu ada yang pernah menanyakan bagaimana menyimpan setting program yang kita buat kedalam document text, dan saya menyarankan di simpan ke dalam bentuk file extension ini saja, karena lebih fleksibel untuk kita baca lagi. Seperti biasanya saya ga jago bermain dengan kata -kata langsung saja kita lihat contoh code berikut :

Siapkan beberapa komponen Tedit dan Button kedalam Form seperti gambar berikut :

Berikut source codenya :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    btnsimpan: TButton;
    edtSMTPServer: TEdit;
    edtSMTPPort: TEdit;
    edtAccount: TEdit;
    edtPassword: TEdit;
    edtEmail: TEdit;
    lbl1: TLabel;
    lbl2: TLabel;
    lbl3: TLabel;
    lbl4: TLabel;
    lbl5: TLabel;
    btnbaca: TButton;
    procedure btnsimpanClick(Sender: TObject);
    procedure btnbacaClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses IniFiles;

{$R *.dfm}


procedure TForm1.btnsimpanClick(Sender: TObject);
var
  MailIni: TIniFile;
begin
  MailIni := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'setting.ini');
  with MailIni do begin
    WriteString('Smtp', 'ServerName', edtSMTPServer.Text);

    WriteString('Smtp', 'ServerPort', edtSMTPPort.Text);

    WriteString('Smtp', 'ServerUser', edtAccount.Text);

    WriteString('Smtp', 'ServerPassword', edtPassword.Text);

    WriteString('Email', 'PersonalEmail', edtEmail.Text);
  end;
  MailIni.Free;
end;

procedure TForm1.btnbacaClick(Sender: TObject);
var
  MailIni: TIniFile;
begin
  MailIni := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'setting.ini');
  with MailIni do begin
    edtSMTPServer.text := ReadString('Smtp', 'ServerName', 'pop3.server.com');
    edtSMTPPort.text := ReadString('Smtp', 'ServerPort', '110');
    edtAccount.text := ReadString('Smtp', 'ServerUser', 'your_login');
    edtPassword.text := ReadString('Smtp', 'ServerPassword', 'your_password');

    edtEmail.text := ReadString('Email', 'PersonalEmail', 'someaddress@somewhere.com');
  end;
  MailIni.Free;
end;

end.
Atau silahkan sedot aja disini atau disini Semoga bermanfaat.

1 komentar:

Blogger mengatakan...

Let me tell you something...

What I'm going to tell you might sound really weird, and maybe even kind of "out there"....

WHAT if you could simply press "PLAY" to listen to a short, "musical tone"...

And magically attract MORE MONEY to your LIFE???

What I'm talking about is BIG MONEY, even MILLIONS of DOLLARS!!!

Do you think it's too EASY??? Think this couldn't possibly be for REAL??

Well then, I'll be the one to tell you the news.

Sometimes the largest blessings life has to offer are the SIMPLEST!!!

In fact, I'm going to provide you with PROOF by letting you PLAY a real-life "magical money tone" I've produced...

You simply press "PLAY" and watch as your abundance angels fly into your life... it starts right away...

CLICK here to play the magical "Miracle Abundance Tone" - as my gift to you!!!

Posting Komentar

Twitter Delicious Facebook Digg Stumbleupon Favorites More