Lire/écrire dans un fichier texte

Procedure NewTxt;
Var
F : Textfile;

Begin
AssignFile(F, 'c:ek.txt'); {Assigns the Filename}
ReWrite(F); {Create a new file named ek.txt}
Writeln(F, 'You have written text into a .txt file');
Closefile(F); {Closes file F}
End;

Procedure OpenTxt;
Var
F : Textfile;

Begin
AssignFile(F, 'c:ek.txt'); {Assigns the Filename}
Append(F); {Opens the file for editing}
Writeln(F, 'You have written text into a .txt file');
Closefile(F); {Closes file F}
End;

Procedure ReadTxt;
Var
F : Textfile;
str:String;

Begin
AssignFile(F, 'c:ek.txt'); {Assigns the Filename}
Reset(F); {Opens the file for reading}
Readln(F,str);
ShowMessage('1. line of textfile:' +str);
Closefile(F); {Closes file F}
End;

procedure TForm1.Button1Click(Sender: TObject);
begin
NewTxt;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
OpenTxt;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
ReadTxt;
end;
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour15/03/2004
VisualisationVu 1822 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Fichier
Auteur de l'article
SwissDelphiCenter SwissDelphiCenter
connecté le 02/11/2011
329 articles dans la section
Contacter l'auteur