AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

INI File Schreiben und auslesen

Ein Thema von floppybe · begonnen am 13. Mär 2014 · letzter Beitrag vom 24. Mär 2014
 
Popov
(Gast)

n/a Beiträge
 
#15

AW: INI File Schreiben und auslesen

  Alt 14. Mär 2014, 07:48
Klein wenig übertrieben der Code, aber es soll ja ein Beispiel sein:
Delphi-Quellcode:
uses
  IniFiles;

const
  LangList = 'Deutsch, Englisch, Französisch, Spanisch'; //Mit Komma getrennte Liste
  IniLangSection = 'Sprachen';
  IniLangList = 'ListeSprachen';
  IniCurLang = 'AktuelleSprache';

function GetIniPath(var IniPath: String): Boolean;
const
  IniSubFolder = 'Ini\';
  IniFileName = 'Einstellungen.ini';
var
  Path: String;
begin
  Path := ExtractFilePath(ParamStr(0));
  IniPath := Path + IniSubFolder + IniFileName;

  Result := ForceDirectories(Path + IniSubFolder);
  if not Result then
    MessageDlg('Fehler. Es konnte kein Ini Ordner angelegt werden.', mtError, [mbOK], 0);
end;

procedure LoadFromIni(ComboBox: TComboBox);
var
  IniFile: TIniFile;
  IniPath: String;
  s: String;
  k: Integer;
begin
  if not GetIniPath(IniPath) then Exit;

  IniFile := TIniFile.Create(IniPath);
  try
    s := IniFile.ReadString(IniLangSection, IniLangList, LangList);
    ComboBox.Items.CommaText := s;
    k := IniFile.ReadInteger(IniLangSection, IniCurLang, 0);
    if (k > -1) and (k < ComboBox.Items.Count) then
      ComboBox.ItemIndex := k;
  finally
    IniFile.Free;
  end;
end;

procedure SaveToIni(ComboBox: TComboBox);
var
  IniFile: TIniFile;
  IniPath: String;
  s: String;
begin
  if not GetIniPath(IniPath) then Exit;

  IniFile := TIniFile.Create(IniPath);
  try
    IniFile.WriteString(IniLangSection, IniLangList, ComboBox.Items.CommaText);
    IniFile.WriteInteger(IniLangSection, IniCurLang, ComboBox.ItemIndex);
  finally
    IniFile.Free;
  end;
end;

procedure AddLanguage(ComboBox: TComboBox; Name: String);
begin
  ComboBox.Items.Add(Name);
end;

procedure TForm1.ButtonLoadClick(Sender: TObject);
begin
  LoadFromIni(ComboBox1);
end;

procedure TForm1.ButtonSaveClick(Sender: TObject);
begin
  SaveToIni(ComboBox1);
end;

procedure TForm1.ButtonAddClick(Sender: TObject);
var
  s: String;
begin
  s := InputBox('Sprache', 'Neue Sprache hinzufügen', '');
  if Trim(s) <> 'then
    AddLanguage(ComboBox1, s);
end;

Geändert von Popov (14. Mär 2014 um 07:53 Uhr)
  Mit Zitat antworten Zitat
 

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:51 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz