Autor Beitrag
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: So 19.02.06 10:06 
erstmal mein Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure tform1.saveextention(path:Tfilename);
var
pbuffer:Pstring;
afile: textfile;
a:integer;
begin
 if fileexists(path) or cancreatefile then
 begin
 assignfile(afile,path);
  try
   rewrite(afile);
   for a:=pextentionlist.Count-1 downto 0 do
   begin
    pbuffer:=pextentionlist.Items[a];
    writeln(afile,pbuffer^);
   end;
   closefile(afile);
  finally
   closefile(afile);
  end;
 end;
end;


wenn path='C:\Dokumente und Einstellungen\Tilo\Anwendungsdaten\TPP\lister\invalid.txt'

dann bekomme ich in Zeile 11 die Meldung: Dateizugriff verweigert.

Bei anderen Ordner z.b. Ordner des Programms gibt es keine Fehlermeldung.
Weiss wer woran das liegt?
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 19.02.06 12:14 
3 Fragen vorab:

1. Du nutzt WindowsXP?
2. Existiert das Verzeichnis, in dem Du speichern willst?
3. Ist dieses Profil-Verzeichnis dein eigenes (das aktuelle User-Profil)?

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Tilo Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: So 19.02.06 16:52 
1) Ja XP
2) Nein, aber auch wenn ich es im WindoofFenster erzeuge(bis auf die Datei, welche erstellt weden soll) kommt der Fehler
3) ja. Der Ordner wird über ein abgeänderte Routiene Von user profile iconLuckie ermitellt.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
function TForm1.getuserPath:string;
{Original Code von Luckie}
//Kommentare Tilo Papke
var
  pidl                   : PItemIdList;
  FolderPath             : string;
  Malloc                 : IMalloc;  //nötig für Speichermanagement
begin
  Malloc := nil;
  FolderPath := '';
  SHGetMalloc(Malloc);  //Adresse holen für shell
  if Malloc = nil then
  begin
    Result := FolderPath;
    Exit;
  end;
  try
    if SUCCEEDED(SHGetSpecialFolderLocation(0, CSIDL_APPDATA, pidl)) then
    begin       //wenn Ermittlung des userOdners erfolgreich dann
      SetLength(FolderPath, max_path); //Maximale Länge
      if SHGetPathFromIDList(pidl, PChar(FolderPath)) then
      begin   //wenn Konvertierung in String erfolgreich
        SetLength(FolderPath, length(PChar(FolderPath))); //kürzen
      end;
    end;
    Result := FolderPath;
  finally
    Malloc.Free(pidl);
  end;
{Ende Original Code Luckie}
end;


Der Aufruf der fehlerhaften Routine erfolgt so:
ausblenden Quelltext
1:
loadextention(getuserpath+'\TPP\lister\invalid.txt');					


Wie gesagt bei anderen Pfaden haut es hin.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 20.02.06 13:39 
Gut, Auf Grund von 1. hätte es auch ein anderer Fehler sein können, der aber durch 3. nicht zutreffend ist (Unter XP wird der Zugriff auf Fremde Profile stark erschwert).

Zu deinem Problem:

Leg doch das Verzeichnis explizit vorher an:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
F := getuserpath+'\TPP\lister\invalid.txt';
If not ForceDirectories(ExtractFilePath(F)) Then
    Raise Exception.Create('Nicht alle benötigten Verzeichnisse konnten angelegt werden!');
//Überprüf jetzt mal mit Luckies Methode für Schreibzugriff, ob Du Berechtigungen zum Erzeugen von Dateien hast (Write Access auf ExtractFilePath(F)

//Wenn diese vorhanden sind, Datei anlegen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Tilo Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Do 23.02.06 15:19 
Danke user profile iconBenBE,
habe es jetzt so gelöst:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
procedure tform1.saveextention(path:Tfilename);
var
pbuffer:Pstring;
afile: textfile;
a:integer;
begin
 if fileexists(path) or cancreatefile then
 begin
 assignfile(afile,path);
  try
   if not (directoryexists(extractfileDir(path))) then
    if not (forcedirectories(extractfileDir(path))) then
     raise exception.Create('Fehler, kan Pfad nocht erstellen');
   rewrite(afile);
   for a:=pextentionlist.Count-1 downto 0 do
   begin
    pbuffer:=pextentionlist.Items[a];
    writeln(afile,pbuffer^);
   end;
   closefile(afile);
  finally
   closefile(afile);
  end;
 end;
end;


Habe damit erstmal keine Probleme!.