Einzelnen Beitrag anzeigen

Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#7

Re: Speichern von Dateien - Windows Vista

  Alt 2. Mai 2009, 15:13
Speicher deine Daten und Dateien da hin wo sie auch hin gehören.

Sichwort Hier im Forum suchenAppData bzw.: In .ini ohne Adminrechte speichern?

Ist also recht einfach:

Delphi-Quellcode:
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.

// Edit: also ebend war noch kein Beitrag ausser dem ersten da... ich werd wohl alt
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat