Einzelnen Beitrag anzeigen

Benutzerbild von jaenicke
jaenicke

Registriert seit: 10. Jun 2003
Ort: Berlin
9.359 Beiträge
 
Delphi 11 Alexandria
 
#40

Re: In .ini ohne Adminrechte speichern?

  Alt 26. Mär 2009, 21:43
Zitat von AlexII:
Ok es klappt jetzt alles
Und wird das auch unter Vista gehen, was meinst du?
Das sollte auch unter Vista normal klappen. In den Anwendungsdaten sollten jedenfalls der Ordnung halber Unterverzeichnisse benutzt werden, das wurde ja schon gesagt. Wie wäre es so, auch mal richtig formatiert:
Delphi-Quellcode:
uses
  ActiveX, ShlObj, IniFiles;

const
  AppDataRootDir = '\AlexII';
  AppDataProjectDir = '\Dein Projektname';
  CSIDL_LOCAL_APPDATA = $001c;

function GetSpecialFolder(aFolder: Integer): String;
var
  pIdL: PItemIDList;
  Path: array [0..Max_Path] of Char;
  Allocator: IMalloc;
begin
  // ItemIdList für den Ordner holen
  SHGetSpecialFolderLocation(0, aFolder, pIdL);
  // ItemIdList in String umwandeln lassen
  SHGetPathFromIDList(pIDL, Path);
  // Speicher wieder freigeben
  if Succeeded(SHGetMalloc (Allocator)) then
    Allocator.Free(pIdL);
  Result := Path;
end;

procedure TForm1.FormShow(Sender: TObject);
var
  Ini: TIniFile;
  UserAppDataDir: String;
begin
  UserAppDataDir := GetSpecialFolder(CSIDL_LOCAL_APPDATA);
  if FileExists(UserAppDataDir + AppDataRootDir + AppDataProjectDir + '\config.ini') then
  begin
    Ini := TIniFile.Create(UserAppDataDir + AppDataRootDir + AppDataProjectDir + '\config.ini');
    try
      ComboBox1.ItemIndex := Ini.ReadInteger('Default', 'Channel', 0);
      TrackBar1.Position := Ini.ReadInteger('Default', 'Volume', 10);
      cbDirectConnection.Checked := Ini.ReadBool('Default', 'Proxy', True);
      ed_ProxyServer.Text := Ini.ReadString('Default', 'ProxyIP', '');
    finally
      ini.free;
    end;
  end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
  Ini: TIniFile;
  UserAppDataDir: String;
begin
  UserAppDataDir := GetSpecialFolder(CSIDL_LOCAL_APPDATA);
  ForceDirectories(UserAppDataDir + AppDataRootDir + AppDataProjectDir);
  Ini := TIniFile.Create(UserAppDataDir + AppDataRootDir + AppDataProjectDir + '\config.ini');
  try
    Ini.WriteInteger('Default', 'Channel', ComboBox1.ItemIndex);
    Ini.WriteInteger('Default', 'Volume', TrackBar1.Position);
    Ini.WriteBool('Default', 'Proxy', cbDirectConnection.Checked);
    Ini.WriteString('Default', 'ProxyIP', ed_ProxyServer.Text);
  finally
    Ini.Free;
  end;
  Action := caFree; // Bringt nur etwas, wenn es nicht im Hauptformular steht
end;
Sebastian Jänicke
Alle eigenen Projekte sind eingestellt, ebenso meine Homepage, Downloadlinks usw. im Forum bleiben aktiv!
  Mit Zitat antworten Zitat