unit Dingsbums;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IniFiles, StdCtrls;
type
TFormX =
class(TForm)
ButtonX: TButton;
LabelX: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
procedure SaveIniFile;
public
{ Public-Deklarationen }
end;
var
FormX: TFormX;
implementation
{$R *.dfm}
uses
ShellAPi,
ShlObj;
const
strAppDataDir = '
\tP.Software\My Testprogramm\';
strIniFName = '
TestIniFile.ini';
function GetShellFolder(CSIDL: integer):
string;
var
pidl: PItemIdList;
FolderPath:
string;
SystemFolder: Integer;
begin
FolderPath := '
';
SystemFolder := CSIDL;
if SUCCEEDED(SHGetSpecialFolderLocation(0, SystemFolder, pidl))
then
begin
SetLength(FolderPath, MAX_PATH);
SHGetPathFromIDList(pidl, PChar(FolderPath));
SetLength(FolderPath, lstrlen(PChar(FolderPath)));
end;
Result := FolderPath;
end;
procedure TFormX.SaveIniFile;
var
IniFile: TIniFile;
AppDataDir:
string;
begin
AppDataDir := GetShellFolder(CSIDL_APPDATA) + strAppDataDir;
if not DirectoryExists(AppDataDir)
then
begin
if not ForceDirectories(AppDataDir)
then
begin
ShowMessage('
Fehler beim erstellen des Ordners: +'#13'
"' + AppDataDir + '
"');
exit;
end;
end;
LabelX.Caption := format('
"%s"', [AppDataDir + strIniFName]);
IniFile := TIniFile.Create(AppDataDir + strIniFName);
try
IniFile.WriteString('
MyText', '
Infotext', '
Hallo');
finally
IniFile.Free;
end;
end;
procedure TFormX.Button1Click(Sender: TObject);
begin
SaveIniFile;
end;
end.