Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#17

AW: INI File Schreiben und auslesen

  Alt 14. Mär 2014, 08:39
@Popov

Hier würden sich Exceptions besser machen, denn nun gibt es auch einen Hinweis, warum der nicht erstellt werden konnte
Delphi-Quellcode:
function GetIniPath : string;
const
  IniSubFolder = 'Ini\';
  IniFileName = 'Einstellungen.ini';
var
  Path: String;
begin
  Path := ExtractFilePath(ParamStr(0));
  Result := Path + IniSubFolder + IniFileName;

  if not ForceDirectories( Path + IniSubFolder ) then
    RaiseLastOSError;
end;

procedure LoadFromIni(ComboBox: TComboBox);
var
  IniFile: TIniFile;
  s: String;
  k: Integer;
begin
  IniFile := TIniFile.Create( GetIniPath );
  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;
  s: String;
begin
  IniFile := TIniFile.Create( GetIniPath );
  try
    IniFile.WriteString(IniLangSection, IniLangList, ComboBox.Items.CommaText);
    IniFile.WriteInteger(IniLangSection, IniCurLang, ComboBox.ItemIndex);
  finally
    IniFile.Free;
  end;
end;
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)

Geändert von Sir Rufo (14. Mär 2014 um 08:41 Uhr)
  Mit Zitat antworten Zitat