this slowpoke moves

Use INI-Data

Hier ein Beispiel, wie man Daten aus einer INI-Datei für die Einstellungen seiner Komponenten nutzen kann.

uses IniFiles

public
    { Public-Deklarationen }
    procedure WriteOptions;
    procedure ReadOptions;


var
  Form1: TForm1;
  TIF : TIniFile;

//

function MainDir : string;
begin
  Result := ExtractFilePath(ParamStr(0));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Label1.Caption := MainDir;
  
end;

procedure TForm1.WriteOptions;    // ################### Options Write
var OPT :string;
begin
   OPT := 'Options';

   if not DirectoryExists(MainDir + 'Options/')
   then ForceDirectories(MainDir + 'Options/');

   TIF := TIniFile.Create(MainDir + 'Options.ini');
   with TIF do
   begin
   WriteBool(OPT,'SaveOptions',CheckBox1.Checked);
   WriteInteger(OPT,'Compress',Combobox1.ItemIndex);
   WriteInteger(OPT,'Overlay',RadioGroup1.ItemIndex);
   Free;
   end;
end;

procedure TForm1.ReadOptions;    // ################### Options Read
var OPT:string;
begin
  OPT := 'Options';
  if FileExists(MainDir + 'Options.ini') then
  begin
  TIF:=TIniFile.Create(MainDir + 'Options.ini');
  with TIF do
  begin
  CheckBox1.Checked:=ReadBool(OPT,'SaveOptions',CheckBox1.Checked);
  Combobox1.ItemIndex:=ReadInteger(OPT,'Compress',combobox1.ItemIndex);
  RadioGroup1.ItemIndex:=ReadInteger(OPT,'Overlay',RadioGroup1.ItemIndex);
  Free;
  end;
  end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  WriteOptions;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
   ReadOptions;
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate