Bonjour,
J'extrais les champs d'une ligne comprenant la structure d'un fichier de messagerie (Orange ici). J'obtiens bien l'extraction des 103 champs que j'écris dans une StringList. Mais lorsque je les affiche dans une listBox, il y a un champ vide qui apparait. Je ne sais pas comment faire pour ne pas enregistrer ce champ vide. Il a lieu lorsque j'ai fini la boucle d'extraction et que je rajoute le dernier champ de la liste...
Je mets en pièce jointe le fichier de la structure StructOrange.txt
Voici le code des deux procédures utilisées:
Et voici la boucle d'extraction:
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 {-----------------------------------------------------------------} procedure TForm2.SpdBtnCalculClick(Sender: TObject); var i : integer; begin if Assigned(ListChamps) then begin ListChamps := fExtractChamps(FicTest,Sep); EdNb.Text := inttostr(ListChamps.Count); if ListChamps.Count > 1 then begin LBChamps.Items.Add('Liste des champs du Fichier '+ExtractFileName(FicTest)+' : '+CR); for i := 0 to ListChamps.Count - 1 do begin LBChamps.Items.Add(ListChamps[i]); if Length(ListChamps[i]) = 0 then showmessage('C''est bien un champ vide qui est lu en '+inttostr(i)+'ème position !'); end; end; end else MessageDlg('La Liste des champs n''a pas été créee!',mtInformation,[mbOk],0); end;
Voilà, si vous avez une idée de pourquoi, il enregistre un champ vide?
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 {--- Fournit une StringList des champs extraits du Fichier fourni -------------} Function fExtractChamps(aFic : String; aSep : ShortString) : TStringList; Var Ftxt : TextFile; LigOrg : String; P : Integer; Champ : ShortString; begin If not fileexists(aFic) then Exit; AssignFile(Ftxt,aFic); P := -1; Try Result := TStringList.Create; reset(Ftxt); Readln(FTxt, LigOrg); Repeat if P <> 0 then begin P := AnsiPos(aSEP,LigOrg); Champ := Copy(LigOrg,1,P - 1); result.Add(Champ); end; if P > 0 then LigOrg := Copy(LigOrg,P + 1,Length(LigOrg) - P); until P = 0; result.Add(LigOrg); finally CloseFile(Ftxt); end; end;
Merci d'avance
Partager