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
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Tfrm_main = class(TForm)
Memo1: TMemo;
btn_ok: TButton;
procedure btn_okClick(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
procedure LoadFileIntoMemo(F: TFilename);
end;
var
frm_main: Tfrm_main;
implementation
{$R *.dfm}
procedure Tfrm_main.FormCreate(Sender: TObject);
begin
if ParamCount = 1 then
begin
//Effectuer test d'usage sur le paramètre (extension, ...)
LoadFileIntoMemo(ParamStr(1));
end;
end;
procedure Tfrm_main.LoadFileIntoMemo(F: TFilename);
begin
with Memo1 do
begin
Clear;
Lines.LoadFromFile(F);
end;
end;
procedure Tfrm_main.btn_okClick(Sender: TObject);
Var F: TextFile;
Stg:String;
begin
//Lire le contenu du fichier
Memo1.Clear; //Efface le contenu de Memo1
//AssignFile(F,ExtractFilePath(Application.ExeName)+'test.txt');
LoadFileIntoMemo(ExtractFilePath(Application.ExeName) + 'test.txt');
Reset(F);
repeat //Repeter...
Readln(F,Stg); //Lit une ligne du fichier texte jusqu'au prochain sut de ligne
Memo1.Lines.Add(Stg); //Affiche dans Memo1 le contenu de la variable
until EOF(F);// ...jusqu'à ce que la position en cours du pointeur se trouve en fin de fichier
CloseFile(F);
end;
end. |
Partager