Einzelnen Beitrag anzeigen

Benutzerbild von thepaul
thepaul

Registriert seit: 7. Nov 2004
Ort: Jena
63 Beiträge
 
Delphi 7 Personal
 
#7

Re: 2 Formulare, 1 IniFile ~> Fehler

  Alt 2. Jan 2005, 17:46
Formular 1:
Delphi-Quellcode:
unit scr_main;

interface

uses
  ..., inifiles, ...

...

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    ini: tinifile;
  end;

var
  frmMain: TfrmMain;

implementation

uses src_Options, src_Info;

{$R *.dfm}

...

procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);

begin
  ini:= TINIFile.Create(ExtractFilePath(ParamStr(0))+'settings.ini');

  try //schreiben der Einstellungen
    ini.WriteBool('output','checkb',checkbox1.Checked);
    ini.WriteBool('output','options',gbxoptionsoutput.Visible);

    ini.WriteInteger('Position','Top',frmMain.Top);
    ini.WriteInteger('Position','Left',frmMain.Left);
  finally
    ini.UpdateFile;
    ini.Free;
  end;
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  ini:= tinifile.Create(ExtractFilePath(ParamStr(0))+'settings.ini');

  try //Einlesen von settings.ini
    checkbox1.Checked:=ini.ReadBool('output','checkb',false);
    gbxoptionsoutput.Visible:=ini.ReadBool('output','options',true);

    frmMain.Left:=ini.ReadInteger('Position','Left', 100);
    frmMain.Top:=ini.ReadInteger('Position','Top',100);
  finally
    ini.Free;
  end;
...

end;

...

procedure TfrmMain.Optionen2Click(Sender: TObject);
begin
  frmOptions.ShowModal;
end;

end.
Formular 2:
Delphi-Quellcode:
unit src_Options;

interface

uses
  ..., inifiles;

...

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    ini:tinifile;
  end;

...

procedure TfrmOptions.BitBtn1Click(Sender: TObject);

begin
  ini:=tinifile.Create(ExtractFilePath(ParamStr(0)+'settings.ini'));

  try
    ini.WriteBool('options','rdb1',rdb1.Checked);
    ini.WriteBool('options','rdb2',rdb2.Checked);
    ini.WriteBool('options','´cbxvisible',combobox1.Visible);
    ini.WriteInteger('options','Index',combobox1.ItemIndex);
  finally
    ini.UpdateFile;
    ini.Free;
    frmoptions.Close;
  end;
end;

...

procedure TfrmOptions.FormCreate(Sender: TObject);

begin
  bitbtn1.default:=True;

  ini:=TINIfile.Create(ExtractFilePath(ParamStr(0)+'settings.ini'));

  try
    rdb1.Checked:=ini.ReadBool('options','rdb1',false);
    rdb2.Checked:=ini.ReadBool('options','rdb2', True);

    combobox1.Visible:=ini.ReadBool('options','cbxvisible',True);
    combobox1.ItemIndex:=ini.ReadInteger('options','Index',0);
  finally
    ini.UpdateFile;
    ini.Free;
  end;
end;

end.
Paul
Mosaic.net - Open Source Mosaik Creator in C#
  Mit Zitat antworten Zitat