AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

RenFile

Ein Thema von Willie1 · begonnen am 27. Jan 2009 · letzter Beitrag vom 28. Jan 2009
Antwort Antwort
Seite 1 von 2  1 2      
Willie1

Registriert seit: 28. Mai 2008
618 Beiträge
 
Delphi 10.1 Berlin Starter
 
#1

RenFile

  Alt 27. Jan 2009, 10:13
Hallo Leute,

der folgende Code löst unter Vista eine "Zugriffsverletzung ... in Modul 'Kernel32.dll' lesen von Adresse 2" aus, unter W98 ist alles in Ordnung.
Woran kann das liegen? Ist RenFile bei Vista geändert worden?
Delphi-Quellcode:
  if MessageDlg(s,mtConfirmation,[mbYes,MbNo,mbHelp],10) = mrYes then begin
    if RenFile(Oldname,Bli.Folder + Newname) then // <--- HIER ------------
    begin
      if Config.CBit[Ord(Confirm)] then ShowMessage('Neuer Namen: "' + Newname + '"');
      BLi.Bildnamen[Bildpos]:=Newname;
      Renamed:=true
    end
  end;
MfG
Willie1
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#2

Re: RenFile

  Alt 27. Jan 2009, 10:16
Was ist den RenFile? Von der Funktion habe ich noch nichts gehört, weder unter Delphi noch kenne ich sie aus der WinAPI.

Und bitte editier deinen Beitrag und ihm einen aussagekräftigeren Titel.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#3

Re: RenFile

  Alt 27. Jan 2009, 10:21
Guten Morgen,

RenFile, ist das eine Win-Api Routine?


Tritt das Problem bei allen möglichen Dateien auf?
Oder tritt es nur bei bestimmten Dateien/Verzeichnissen auf?

Grüße
Klaus
Klaus
  Mit Zitat antworten Zitat
Willie1

Registriert seit: 28. Mai 2008
618 Beiträge
 
Delphi 10.1 Berlin Starter
 
#4

Umbenennen von Files mit Windows

  Alt 27. Jan 2009, 10:40
Sorry, ich habe meine Frage mit "zu heißer Nadel gestrickt"!

Eigene Funktion RenFile sieht so aus:

Delphi-Quellcode:
  function RenFile(const Oldname,Newname: string): Boolean;
  var
    SHFOS: TSHFileOpStruct;
    a,n: array[0..255] of Char;
  begin
    if FileExists(Oldname) then begin
      FillChar(a, SizeOf(a), 0);
      StrPCopy(a, ExpandFilename(Oldname)+#0#0);
      FillChar(n, SizeOf(n), 0);
      StrPCopy(n, ExpandFilename(Newname)+#0#0);
      with SHFOS do begin
        Wnd:=0;
        wFunc:=FO_RENAME;
        pFrom:=a;
        pTo:=n;
        fFlags:=FOF_SIMPLEPROGRESS;
        fAnyOperationsAborted:=false;
        hNameMappings:=nil;
      end;
      Result:=(ShFileOperation(SHFOS) = 0) and
              (SHFOS.fAnyOperationsAborted = LongBool(false)) and FileExists(NewName)
    end
    else
      Result:=false
  end; {RenFile}
Der Fehler tritt bei beliebigen Dateien und Pfaden nur unter Vista auf.
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#5

Re: RenFile

  Alt 27. Jan 2009, 10:44
Und an welcher Stelle in der Funktion tritt die Zugriffsverletzung genau auf? Und welche Entwicklungsumgebung wird genutzt?

Und der Titel ist immer noch recht unbefriedigend. Vorschlag: "Datei umbenennen mit ShFileOperation schlägt unter Vista fehl"
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.140 Beiträge
 
Delphi 12 Athens
 
#6

Re: RenFile

  Alt 27. Jan 2009, 10:50
auch wen es nicht DER Fehler ist

Delphi-Quellcode:
// statt
(SHFOS.fAnyOperationsAborted = LongBool(false))

// lieber
not SHFOS.fAnyOperationsAborted
LongBool(false) ist zwar immer 0, aber LongBool(true) ... nja, vorallem für die WinAPI ist =LongBool(true) nicht immer das Selbe
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#7

Re: RenFile

  Alt 27. Jan 2009, 11:00
.. mag das eventuell damit etwas zu tun haben:


There are two versions of this structure, an ANSI version (SHFILEOPSTRUCTA) and a Unicode version (SHFILEOPSTRUCTW). The Unicode version is identical to the ANSI version, except that wide character strings (LPCWSTR) are used in place of ANSI character strings (LPCSTR). On Microsoft Windows 98 and earlier, only the ANSI version is supported. On Microsoft Windows NT 4.0 and later, both the ANSI and Unicode versions of this structure are supported. SHFILEOPSTRUCTW and SHFILEOPTSTRUCTA should never be used directly; the appropriate structure is redefined as SHFILEOPSTRUCT by the precompiler depending on whether the application is compiled for ANSI or Unicode.
SHNAMEMAPPING has similar ANSI and Unicode versions. For ANSI applications, hNameMappings points to an int followed by an array of ANSI SHNAMEMAPPING structures. For Unicode applications, hNameMappings points to an int followed by an array of Unicode SHNAMEMAPPING structures. However, on Windows NT 4.0 and later, SHFileOperation always returns a handle to a Unicode set of SHNAMEMAPPING structures. If you want applications to be functional with all versions of Windows, the application must employ conditional code to deal with name mappings. For example:

Copy Code
Code:
x = SHFileOperation(&shop);

if (fWin9x)
   HandleAnsiNameMappings(shop.hNameMappings);
else
   HandleUnicodeNameMappings(shop.hNameMappings);
Treat hNameMappings as a pointer to a structure whose members are a UINT value followed by a pointer to an array of SHNAMEMAPPING structures, as seen in its declaration:


Quelle

Grüße
Klaus
Klaus
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.140 Beiträge
 
Delphi 12 Athens
 
#8

Re: RenFile

  Alt 27. Jan 2009, 11:15
es kommt dann darauf an, welche Version Delphi aufruft.

die WinAPI kennt SHFileOperation garnicht
Delphi 2009 leitet SHFileOperation nach SHFileOperationW um
und alles andere nach SHFileOperationA

SHFileOperationA ist ANSI
und SHFileOperationW demnach Unicode

ja und Win98 kennt standardmäßig kein Unicode (aber da sollte das Programm garnicht erst starten, wenn SHFileOperationW fest eingebunden ist, da dort der ProgrammLoader meckern sollte)
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Willie1

Registriert seit: 28. Mai 2008
618 Beiträge
 
Delphi 10.1 Berlin Starter
 
#9

Re: RenFile

  Alt 27. Jan 2009, 11:18
Luckie,
ich benutze die Bibliothek GDIAPI von http://www.progdigy.com, die sich nach meinem jetzigen Kenntisstand nur mit D6/7 kompilieren lässt. Das hat aber mit dem Problem nichts zu tun.

Also Delphi 6.

Ich werde mit euren Tipps (Danke Klaus + himitsu) versuchen das Problem zu lösen und melde mich später nochmal.

Gruß W.
  Mit Zitat antworten Zitat
Progman

Registriert seit: 31. Aug 2007
Ort: 99974 MHL
695 Beiträge
 
Delphi 10.1 Berlin Starter
 
#10

Re: RenFile

  Alt 27. Jan 2009, 11:56
Warum wird nicht die Function RenameFile() genutzt? Die ist (mind.) ab Delphi6 in allen Delphi-Versionen vorhanden und geht auch unter Vista, bei vorhanden Schreibrechten)
Karl-Heinz
Populanten von Domizilen mit fragiler, transparenter Aussenstruktur sollten sich von der Translation von gegen Deformierung resistenter Materie distanzieren!
(Wer im Glashaus sitzt sollte nicht mit Steinen werfen)
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:32 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz