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;