Thema: Delphi Relativer Pfad & co.

Einzelnen Beitrag anzeigen

Super_Chemiker

Registriert seit: 16. Nov 2008
111 Beiträge
 
Delphi 2009 Professional
 
#10

Re: Relativer Pfad & co.

  Alt 26. Mai 2009, 16:00
Delphi-Quellcode:
function TForm1.GetSpecialFolder(hWindow: HWND; Folder: Integer): String;
var
  pMalloc: IMalloc;
  pidl: PItemIDList;
  Path: PChar;
begin
  // get IMalloc interface pointer
  if (SHGetMalloc(pMalloc) <> S_OK) then
  begin
    MessageBox(hWindow, 'Couldn''t get pointer to IMalloc interface.',
               'SHGetMalloc(pMalloc)', 16);
    Exit;
  end;

  // retrieve path
  SHGetSpecialFolderLocation(hWindow, Folder, pidl);
  GetMem(Path, MAX_PATH);
  SHGetPathFromIDList(pidl, Path);
  Result := Path;
  FreeMem(Path);

  // free memory allocated by SHGetSpecialFolderLocation
  pMalloc.Free(pidl);
end;
Der Teil für die GetSpecialFolder funktion

Delphi-Quellcode:
...
    Game := TStringlist.Create;
    try
      ForceDirectories(GetSpecialFolder(Handle, CSIDL_PERSONAL )+'/Saves');
      Game.LoadFromFile(GetSpecialFolder(Handle, CSIDL_PERSONAL )+'/Saves/'+NameF+'.txt');
...
Hier wird eine Datei geladen, falls sie vorhanden ist und der Pfad wird davor erstellt(wenn ich ForceDirectories vor das try schiebe änderts auch nichts)

Delphi-Quellcode:
...
Game.SaveToFile(GetSpecialFolder(Handle, CSIDL_PERSONAL )+'/Saves/'+NameF+'.txt');
...
Hier kommt dann der Fehler


Und natürlich setze ich Game nachher immer auf .Free
  Mit Zitat antworten Zitat