Bonjour,
je souhaite passé un tableau dynamique en paramètre à une fonction.
Cett fonction récupère la liste des fichier dans un dossier avec leur icone associé et la stocke dans un tableau de type TFileInfo que j'ai crée.
Ma fonction se trouve dans une autre unité.
Code de la focntion
Lorsque j'appelle la fonction comme ceci depuis ma fenêtre
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
33
34
35
36
37
38
39
40
41
42 type //Structure contenant les éléments caractéristiques d'un fichier TFileInfo = record {$IFDEF MSWINDOWS} FindData : TWin32FindData platform; {$ENDIF} Info : SHFILEINFO; end; type TTFileInfo = array of TFileInfo; function RecupererInfosFichiersDuDossier(Infos : TTFileInfo;szDossier : string) : integer; var i : integer; hFichier : THandle; begin //On initialise le compteur i := 0; //On test si le dernier caractères est bien un \ if AnsiLastChar(szDossier)^ <> '\' then szDossier := szDossier + '\'; //On trouve le premier fichier hFichier := FindFirstFile(PChar(szDossier+'*.*'), Infos[i].FindData); //On test le handle de ce fichier if hFichier <> INVALID_HANDLE_VALUE then begin repeat //On test si c'est un dossier if Infos[i].FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY <> FILE_ATTRIBUTE_DIRECTORY then begin //On récupère les Infos lié aux icones SHGetFileInfo(PChar(szDossier+Infos[i].FindData.cFileName),0,Infos[i].Info,sizeof(Infos[i].Info),SHGFI_LARGEICON or SHGFI_SYSICONINDEX); //On incrémente le compteur Inc(i); //On ajout une case au tableau //SetLength(Infos,High(Infos)+1); end; //On récupère le fichier suivant until FindNextFile(hFichier,Infos[i].FindData) = false; end; Windows.FindClose(hFichier); Result := i; end;
il n'y a pas de problème cela marche, le seul hic c'est que je ne sais pas combien de fichier il y a dans le dossier quand je fais mon SetLength().
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 var Fichiers : TTFileInfo; begin SetLength(Fichiers,16); //Remplissage de la zone nb_fichier := RecupererInfosFichiersDuDossier(Fichiers, Edit1.Text);
Je donc mis le SetLength() dans ma fonction en rajoutant un élément à ce tableau pour chaque fichier trouvé mais la variable Fichiers :TTFileInfo ne repercute pas le SetLength()
Comment faire?
Merci
Partager