Einzelnen Beitrag anzeigen

jbg

Registriert seit: 12. Jun 2002
3.483 Beiträge
 
Delphi 10.1 Berlin Professional
 
#14

Re: Allgemeine Pfadangabe unter Delphi

  Alt 30. Dez 2006, 14:49
Zitat von Ykcim:
Pfad:=ExtractFilePath(ParamStr(0));
Template:=(Pfad+'Main.dot');
Viel Spaß bei Windows Vista bzw. Win2000/XP ohne Schreibrechte auf das Verzeichnis.

Folgender Code liefert dir das "C:\Dokumente und Einstellungen\BENUTZER\Anwendungsdaten\MYAPPNAME" Verzeichnis.
Delphi-Quellcode:
uses
  Windows, ShlObj;

function GetAppDataDir: string;
var
  Malloc: IMalloc;
  pidl: PItemIDList;
  Buffer: string;
begin
  Result := '';
  { Windows 95 compatible way, Win98 supports SHGetSpecialFolderPath() }
  SHGetMalloc(Malloc);
  if SHGetSpecialFolderLocation(Application.Handle, CSIDL_APPDATA, pidl) = S_OK then
  begin
    try
      SetLength(Buffer, MAX_PATH + 1);
      if SHGetPathFromIDList(pidl, PChar(Buffer)) then
        Result := ExcludeTrailingPathDelimiter(Copy(Buffer, 1, StrLen(PChar(Buffer))));
    finally
      Malloc.Free(pidl);
    end;
  end;
end;

function GetMyAppDataDir(const AppName: string): string;
begin
  Result := GetAppDataDir;
  if AppName <> 'then
    Result := Result + '\' + AppName;
  ForceDirectories(Result); // create directory structure
end;


...
begin
  Template := GetMyAppDataDir('MyAppName') + '\Main.dot';
end;
  Mit Zitat antworten Zitat