[Renommé] Erreur recherche de fichiers

Résolu
MiniApp Messages postés 654 Date d'inscription lundi 21 juillet 2014 Statut Membre Dernière intervention 22 février 2019 - Modifié par Whismeril le 28/10/2014 à 16:23
bravemouse Messages postés 74 Date d'inscription jeudi 8 mars 2012 Statut Membre Dernière intervention 2 avril 2019 - 30 oct. 2014 à 14:58
Bonjour

Mon code suivant bug

procedure TFileListView.UpdtFiles;
var
IndexFile,FileCount:Cardinal;
TempIcon:TIcon;
IndexIcon:Word;
Attr:WIN32_FIND_DATA;
Shell32DLLHandle,Kernel32DLLHandle,SearchHandle:THandle;
DLLExtractAssociatedIcon:function(hInst: HINST; lpIconPath: PWideChar;
  var lpiIcon: Word): HICON; stdcall;
DLLFindNextFile:function(hFindFile: THandle; var lpFindFileData: TWIN32FindData): BOOL; stdcall;
begin
Try
  //Préparation

    if Assigned(FOnProgress) then
      FOnProgress(Self,FLVUPSPrepa,0,1);
    IndexIcon := 0;
    IndexFile := 0;
    FileCount := 0;
    TempIcon := TIcon.Create;
    TempIcon.SetSize(32,32);
    ImgList.Clear;
    Items.Clear;
  {Chargement des DLL
  Information: ce code à été trouver sur developpez.com et a été publier par Olivier Lance
  Lien:http://olance.developpez.com/articles/delphi/creation-dll/ (25/10/2014)
  Le code ici présent est modifier}
  if Assigned(FOnProgress) then
    FOnProgress(Self,FLVUPSLoadShell32DLL,0,1);
  Shell32DLLHandle := LoadLibrary('shell32.dll');//Chargement de Shell32.dll
  if Shell32DLLHandle = 0 then
    EFileListView.Create('shell32.dll n''a pas pu être charger');
  DLLExtractAssociatedIcon := GetProcAddress(Shell32DLLHandle,'ExtractAssociatedIconW');//Chargement de la fonction

  if Assigned(FOnProgress) then
    FOnProgress(Self,FLVUPSLoadKernel32DLL,0,1);
  Kernel32DLLHandle := LoadLibrary('kernel32.dll');//Chargement de kernel32.dll
  if Kernel32DLLHandle = 0 then
    EFileListView.Create('kernel32.dll n''a pas pu être charger');
  DLLFindNextFile := GetProcAddress(Kernel32DLLHandle,'FindNextFileW');//Chargement de la fonction
  //***
  //Recherche
  //évaluation du nombre de fichier
    SearchHandle := FindFirstFile(Pchar(FDirectory+'\'+Mask),Attr);
    while DLLFindNextFile(SearchHandle,Attr)=True do
      begin
        Inc(FileCount);
        if Assigned(FOnProgress) then
          FOnProgress(Self,FLVUPSSearchFileCount,FileCount,0);
      end;
    SetLength(FilesProperties,IndexFile+5);
  //Recherche des fichiers
    IndexFile := 0;
    SearchHandle := FindFirstFile(PChar(FDirectory+'\'+Mask),Attr);
    Repeat
      begin
        if Assigned(FOnProgress) then
          FOnProgress(Self,FLVUPGetFiles,IndexFile,FileCount);
        if (attr.cFileName = PChar('.'))or(attr.cFileName = '..') then
          if attr.cFileName = PChar('.') then
            begin
              if FCurrentDirName <> '$HIDE-DIR$' then
                With Items.Add do
                  begin
                    Caption := FCurrentDirName;
                    if Assigned(FCurrentDirIcon) then
                      ImageIndex := ImgList.AddIcon(FCurrentDirIcon)
                    else ImageIndex := ImgList.AddIcon(FInvalidIconFile)
                  end;
              end;
          if attr.cFileName = '..' then
            begin
              if FParentDirName <> '$HIDE-DIR$' then
                With Items.Add do
                  begin
                    Caption := FParentDirName;
                    if Assigned(FCurrentDirIcon) then
                      ImageIndex := ImgList.AddIcon(FCurrentDirIcon)
                    else ImageIndex := ImgList.AddIcon(FInvalidIconFile)
                  end;
            end
        Else With Items.Add do
              begin
                Caption := Attr.cFileName;
                TempIcon.Handle := DLLExtractAssociatedIcon(Application.Handle,PWideChar(FDirectory+'\'+Attr.cFileName),indexIcon);
                if (TempIcon.Height or TempIcon.Width)<>32 then
                  ImageIndex := ImgList.AddIcon(FInvalidIconFile)
                Else ImageIndex := ImgList.AddIcon(TempIcon);
              end;
        FilesProperties[IndexFile] := Attr;
      end;
    Until DLLFindNextFile(SearchHandle,Attr)<>True;
    if Assigned(FOnProgress) then
      FOnProgress(Self,FLVUPGetFiles,IndexFile,FileCount);
Finally
  FindClose(SearchHandle);
  TempIcon.Free;
  FreeLibrary(Shell32DLLHandle);
  FreeLibrary(Kernel32DLLHandle);
End;
end;


Je ne sais pas où mais il bug (c'est dans la Recherche des fichiers) : il me fait l'erreur une erreur de violation d'acces à l'adresse 0x00409D6E écriture de l'addresse 0x000804c0 (en anglais) et la fenêtre CPU indique que l'adresse 0x00409D6E contient le code asm :
Push EAX
(qui a déjà été éxécuter plus haut) dans si j'ai bien interprêté la procedure LoadResString:

Voici un extrait de la déclaration :

TFileLstViewUpdtProgressState = (FLVUPSPrepa,FLVUPSLoadShell32DLL,FLVUPSLoadKernel32DLL,
  FLVUPSSearchFileCount,FLVUPGetFiles,FLVUPFinish);
  TFileLstViewUpdtProgressEvent=procedure(Sender:TObject;State:TFileLstViewUpdtProgressState;
  CurrentFile,FileCount:Integer)of object;
  EFileListView = Exception;
  TFileListView = class(TCustomListView)
  private
    { Déclarations privées }
    FParentDirName,FCurrentDirName:String;
    FParentDirIcon,FCurrentDirIcon,FInvalidIconFile:TIcon;
  protected
    { Déclarations protégées }
    FMask,FDirectory:String;
    ImgList:TImageList;
    FilesProperties: array of WIN32_FIND_DATA;
    FOnProgress:TFileLstViewUpdtProgressEvent;
    procedure UpdtFiles;
  published
    { Déclarations publiées }
    property Mask:String read FMask write SetMask;
      //Indique le masque
    property ParentDirName:String read FParentDirName write FParentDirName;
      //Indique le nom du dossier '..'. $HIDE-DIR$ cache ce dossier.
    property CurrentDirName:String read FCurrentDirName write FCurrentDirName;
      //Indique le nom du dossier '.'. $HIDE-DIR$ cache ce Dossier
    property ParentDirIcon:TIcon read FParentDirIcon write SetParentDirIcon;
      //Indique l'icone du dossier '..'.
    property CurrentDirIcon:TIcon read FCurrentDirIcon write SetCurrentDirIcon;
      //Indique l'icone quand l'icone du fichier est trop petite
    property InvalidIconFile:TIcon read FInvalidIconFile write SetInvalidIconFile;
      //Indique l'icone du dossier '.'.
  end;


Chercher et essayer : vous trouverez la solution!
Fouiner et regarder partout : vous trouverez la connaissance!!

6 réponses

bravemouse Messages postés 74 Date d'inscription jeudi 8 mars 2012 Statut Membre Dernière intervention 2 avril 2019
27 oct. 2014 à 23:24
bonjour Monsieur : MiniApp
Voici cette Bibliothèque ( With Full Source ) et leur Nom est Ultimate ... Veuillez le Télécharger depuis ce Lien et essayer de installer et compiler les démos dans le fichier Nommer Bonus , peut être vous pouvez trouver La solution dans le sous fichier iconlist ..
voici le lien : http://www.4shared.com/rar/9ruS5DKrba/ultimate.html
0
MiniApp Messages postés 654 Date d'inscription lundi 21 juillet 2014 Statut Membre Dernière intervention 22 février 2019 5
28 oct. 2014 à 15:19
Merci mais malheureusement je n'arrive pas à la télécharger :-(. Tu peux la poster comme code-source. sur CCM
0
bravemouse Messages postés 74 Date d'inscription jeudi 8 mars 2012 Statut Membre Dernière intervention 2 avril 2019
29 oct. 2014 à 02:48
voici un autre Lien : http://www.gigabase.com/getfile/kVoNfh-7qg6T8c3rJoLROwBB/ultimate.rar.html
malheureusement j"ai pas du temps en se Moment Pour faire Traité cette Bibliothèque ...; a vous de Jouer Monsieur : MiniApp
Cordialement : Brave
0
Whismeril Messages postés 19027 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 24 avril 2024 656
28 oct. 2014 à 16:24
Bonjour, j'ai renommé ton sujet Cdoqe qui bug ne veut rien dire et risque au plus que ceux qui s'y connaisent en recherche de fichier ne le lise pas.
0
MiniApp Messages postés 654 Date d'inscription lundi 21 juillet 2014 Statut Membre Dernière intervention 22 février 2019 5
29 oct. 2014 à 09:40
Merci Bravemouse je vais voir le code.
0
MiniApp Messages postés 654 Date d'inscription lundi 21 juillet 2014 Statut Membre Dernière intervention 22 février 2019 5
30 oct. 2014 à 10:52
Je viens de voir le code et je ne trouve toujours le bug dans mon code (à croire que c'est mon Delphi). Sinon j'ai fait un pas à pas et ça a bugger ici :
if (TempIcon.Height or TempIcon.Width)<>32 then
  ImageIndex := ImgList.AddIcon(FInvalidIconFile)
  Else ImageIndex := ImgList.AddIcon(TempIcon);
(je suis aller un peu vite et j'ai pas vu) mais au moins je sais que c'est plus précisement où ça qui plante. Sinon merci quand même Bravemouse ;-) (je pourrais piquer des codes dans Ultimate).
0
MiniApp Messages postés 654 Date d'inscription lundi 21 juillet 2014 Statut Membre Dernière intervention 22 février 2019 5
Modifié par MiniApp le 30/10/2014 à 12:59
Je me suis tromper en fait c'est juste au dessus à
TempIcon.Handle := DLLExtractAssociatedIcon(Application.Handle,PWideChar(FDirectory+'\'+Attr.cFileName),indexIcon);
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
MiniApp Messages postés 654 Date d'inscription lundi 21 juillet 2014 Statut Membre Dernière intervention 22 février 2019 5
30 oct. 2014 à 13:39
J'ai trouver le bug c'est la conversion en PChar qui bug.
0
bravemouse Messages postés 74 Date d'inscription jeudi 8 mars 2012 Statut Membre Dernière intervention 2 avril 2019
30 oct. 2014 à 13:48
bravo Monsieur MiniApp là Vous êtes Unique ...
Bon courage Pour les Autres ....
0
MiniApp Messages postés 654 Date d'inscription lundi 21 juillet 2014 Statut Membre Dernière intervention 22 février 2019 5
30 oct. 2014 à 14:13
RESOLU!!!

Un jour j'avait un code (ici sur codes-sources je croit) qui permet d'afficher des fichiers dans un MainMenu ou un TPopupMenu. Je lui dit merci car il m'a permit de savoir lister des fichiers. J'ai repartir à 0 car le code ne me corespondait pas. La personne à dut tomber sur le même problême et a trouver la solution :

Mon code resemble désormais à ça :
procedure TFileListView.UpdtFiles;
var
TmpChar:array[0..2048] of char;//NOUVEAUTES ICI<<<<<<<
IndexFile,FileCount:Cardinal;
TempIcon:TIcon;
IndexIcon:Word;
Attr:WIN32_FIND_DATA;
Shell32DLLHandle,Kernel32DLLHandle,SearchHandle:THandle;
DLLExtractAssociatedIcon:function(hInst: HINST; lpIconPath: PWideChar;
  var lpiIcon: Word): HICON; stdcall;
DLLFindNextFile:function(hFindFile: THandle; var lpFindFileData: TWIN32FindData): BOOL; stdcall;
begin
Try
  //Préparation
    if Assigned(FOnProgress) then
      FOnProgress(Self,FLVUPSPrepa,0,1);
    IndexIcon := 0;
    IndexFile := 0;
    FileCount := 0;
    TempIcon := TIcon.Create;
    TempIcon.SetSize(32,32);
    ImgList.Clear;
    Items.Clear;
  {Chargement des DLL
  Information: ce code à été trouver sur developpez.com et a été publier par Olivier Lance
  Lien:http://olance.developpez.com/articles/delphi/creation-dll/ (25/10/2014)
  Le code ici présent est modifier}
  if Assigned(FOnProgress) then
    FOnProgress(Self,FLVUPSLoadShell32DLL,0,1);
  Shell32DLLHandle := LoadLibrary('shell32.dll');//Chargement de Shell32.dll
  if Shell32DLLHandle = 0 then
    EFileListView.Create('shell32.dll n''a pas pu être charger');
  DLLExtractAssociatedIcon := GetProcAddress(Shell32DLLHandle,'ExtractAssociatedIconW');//Chargement de la fonction

  if Assigned(FOnProgress) then
    FOnProgress(Self,FLVUPSLoadKernel32DLL,0,1);
  Kernel32DLLHandle := LoadLibrary('kernel32.dll');//Chargement de kernel32.dll
  if Kernel32DLLHandle = 0 then
    EFileListView.Create('kernel32.dll n''a pas pu être charger');
  DLLFindNextFile := GetProcAddress(Kernel32DLLHandle,'FindNextFileW');//Chargement de la fonction
  //***
  //Recherche
  //évaluation du nombre de fichier
    SearchHandle := FindFirstFile(Pchar(FDirectory+'\'+Mask),Attr);
    while DLLFindNextFile(SearchHandle,Attr)=True do
      begin
        Inc(FileCount);
        if Assigned(FOnProgress) then
          FOnProgress(Self,FLVUPSSearchFileCount,FileCount,0);
      end;
    SetLength(FilesProperties,IndexFile+5);
  //Recherche des fichiers
    IndexFile := 0;
    SearchHandle := FindFirstFile(PChar(FDirectory+'\'+Mask),Attr);
    Repeat
      begin
        if Assigned(FOnProgress) then
          FOnProgress(Self,FLVUPGetFiles,IndexFile,FileCount);
        if (attr.cFileName = PChar('.'))or(attr.cFileName = '..') then
          if attr.cFileName = PChar('.') then
            begin
              if FCurrentDirName <> '$HIDE-DIR$' then
                With Items.Add do
                  begin
                    Caption := FCurrentDirName;
                    if Assigned(FCurrentDirIcon) then
                      ImageIndex := ImgList.AddIcon(FCurrentDirIcon)
                    else ImageIndex := ImgList.AddIcon(FInvalidIconFile)
                  end;
              end;
          if attr.cFileName = '..' then
            begin
              if FParentDirName <> '$HIDE-DIR$' then
                With Items.Add do
                  begin
                    Caption := FParentDirName;
                    if Assigned(FCurrentDirIcon) then
                      ImageIndex := ImgList.AddIcon(FCurrentDirIcon)
                    else ImageIndex := ImgList.AddIcon(FInvalidIconFile)
                  end;
            end
        Else With Items.Add do
              begin
                Caption := Attr.cFileName;//Affichage du nom du fichier
                TempIcon.ReleaseHandle;//Libération du Handle
                StrCopy(TmpChar,PChar(FDirectory+'\'+Attr.cFileName));//Copy du String//NOUVEAUTES ICI<<<<<<<
                TempIcon.Handle := ExtractAssociatedIcon(Application.Handle,TmpChar,indexIcon);//Extraction de l'icone
                if (TempIcon.Height or TempIcon.Width)<>32 then
                  ImageIndex := ImgList.AddIcon(FInvalidIconFile)
                Else ImageIndex := ImgList.AddIcon(TempIcon);
              end;
        FilesProperties[IndexFile] := Attr;
      end;
    if Assigned(FOnProgress) then
      FOnProgress(Self,FLVUPGetFiles,IndexFile,FileCount);
    Until DLLFindNextFile(SearchHandle,Attr)<>True;
finally
  FindClose(SearchHandle);
  TempIcon.Free;
  FreeLibrary(Shell32DLLHandle);
  FreeLibrary(Kernel32DLLHandle);
end;
end;


Maintenant j'utilise un Array of Char apperement plus stable que PChar (Pas sécurisé d'après l'aide). J'utilise StrCopy pour affecter cet array of char.
0
bravemouse Messages postés 74 Date d'inscription jeudi 8 mars 2012 Statut Membre Dernière intervention 2 avril 2019
30 oct. 2014 à 14:58
si votre prob est résolu .. vous pouvez le partager avec les Autres Comme petite Application explique exactement la solution idéal ...
si non vous avez le choix Monsieur MiniApp ..
cordialement : brave.
0
Rejoignez-nous