Lecture et ecriture fichier txt
bonjour,
Je souhaite ecrire et lire dans un fichier txt.
Voici mon programme
Code:
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
| procedure TForm1.Button2Click(Sender: TObject);
Var
Fich_out : TextFile;
Ligne_out : string;
i : integer;
begin
//lire tous les fichier
assignFile(fich_OUT,'d:\toto.txt');
reset(fich_out);
ComboBox1.Clear;
while not eof (fich_out)
do begin
readln(fich_out,Ligne_out);
ComboBox1.Items.Add(Ligne_out);
end;
CloseFile(Fich_out);
rewrite(fich_out);
//Ecriture des ancienne ligne
For i:=0 to combobox1.Items.count-1
do begin
Ligne_out:=ComboBox1.Items[i];
writeLn(Fich_out,Ligne_out);
end;
Writeln(Fich_out,'toto');
//Ecriture de la nouvelle ligne
CloseFile(Fich_out);
end; |
Je trouve cette methode tres bete car je suis obliger de recrire tous le fichier.
Avez vous d'autre methode plus simple ?