delphi 如何实现逐行读取.txt文件并显示实时显示

2025-02-26 06:22:35
推荐回答(3个)
回答1:

打开文件 assign
reset一下
定位到文件最后一行
readln
显示内容,
关闭文件

定时器在20s后重新启动上面的步骤

回答2:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
memo1.Lines.LoadFromFile('1.txt');
end;

end.

回答3:

assignfile
reset
repeat
read
sleep(20*1000);
until
closefile