Bonjour à tous et à toutes.
J'utilise actuellement ceci pour lire un fichier text qui comporte pour chaque ligne la meme dimension (meme longueur)
J'obtiens donc un TStringList comportant aucun doublon sur __NumCompte.
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 Type PFileStrucAPI = ^TFileStrucAPI; TFileStrucAPI = packed record private __NumFact : array[0..7] of AnsiChar; // 8 private __NumCompte : array[0..8] of AnsiChar; // 8 private __Date : array[0..5] of AnsiChar; // 6 private __LibelleManuel : array[0..59] of AnsiChar; // 60 private __Debit : array[0..19] of AnsiChar; // 20 private __Credit : array[0..19] of AnsiChar; // 20 private __RepEcheances : array[0..259] of AnsiChar; // 260 private __RepAnalytique : array[0..399] of AnsiChar; // 400 private __Devise : array[0..7] of AnsiChar; // 8 private __Cours : array[0..19] of AnsiChar; // 20 private __LibellePiece : array[0..59] of AnsiChar; // 60 private __FlagPiece : array[0..0] of AnsiChar; // 1 private __Quantite : array[0..14] of AnsiChar; // 14 private __Unite : array[0..2] of AnsiChar; // 3 private __Reserve : array[0..29] of AnsiChar; // 30 private __FinECR : array[0..1] of AnsiChar; // 2 private __NomLogiciel : array[0..59] of AnsiChar; // 60 private __CodeDossier : array[0..59] of AnsiChar; // 60 private __TypeDeLaPiece : array[0..59] of AnsiChar; // 60 private __IdentDGI : array[0..29] of AnsiChar; // 30 private __InfoLibre : array[0..119] of AnsiChar; // 120 private __FinLigne : array[0..1] of AnsiChar; // 2 end; Const SizeOfFileStrucAPI = SizeOf(TFileStrucAPI); implementation //LECTURE PARTIELLE {$REGION LECTURE PARTIELLE} function ApiCompteNodup(Fichier: TStringList;Chemin, BaseAccess:string): TStringList; var FV : TFileView; i,n, count : Integer; Cnx : TADOConnection; Qry : TADOQuery; NbFichiers : Integer; begin result := TStringList.Create; result.sorted := True; result.duplicates := dupIgnore; NbFichiers := Fichier.Count; Dossier := TStringList.Create; Logiciel := TStringList.Create; Dossier.Duplicates := dupAccept; Logiciel.Duplicates := dupAccept; for i := 0 to NbFichiers - 1 do begin FV := TFileView.Create(Trim(Fichier[i])); try if FV.Loaded then begin Count := ((FV.FileSize) div SizeOfFileStrucApi); // nombre d'elements for n := 0 to count-1 do begin if n = 0 then begin Dossier.Add(Trim(PFileStrucAPI(Pointer(Integer(FV.View) + (SizeOfFileStrucAPI*n)))^.__CodeDossier)); Logiciel.Add(Trim(PFileStrucAPI(Pointer(Integer(FV.View) + (SizeOfFileStrucAPI*n)))^.__NomLogiciel)); end; Result.Add(Trim(PFileStrucAPI(Pointer(Integer(FV.View) + (SizeOfFileStrucAPI*n)))^.__NumCompte)); end; end; finally FV.Free; end; end; // ... end; {$ENDREGION LECTURE PARTIELLE}
Mais je suis maintenance face une fichier qui n'a pas là même longueur pour chaque ligne donc
Count := ((FV.FileSize) div SizeOfFileStrucApi); // nombre d'elements
est erronée et je ne peux pas parcourir chaque ligne.
Est-il possible avec le TFileView de faire un parcourir de chaque ligne sachant qu'au bout de chaque ligne j'ai un 0D0A
Merci.
Vous pouvez retrouvez l'unite FView ici
Ps : le sujet INITIAL
Partager