delphi读取文本(一行一行读入)

来源:百度知道 编辑:UC知道 时间:2024/05/23 19:03:45
各位大侠,小弟向各位请教一个关于DELPHI读取文本的问题,
思路是这样的,用delphi打开问本,按一下Button1控件,EXIT1.TEXT控件则显示第一行,再按一下,则显示第二行,请问这个有没办法实现呢~希望能给出详细的代码,小弟在此万分感谢!!!!

——————————————回答是能!

用了几个全局变量,把你想要的程序搞出来了(不算太难^-^)。我运行了一下,没有问题!源码如下:

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
mylist:TStringlist;
i,a:integer;{i用来统计mylist的count,判断是不是到了mylist的最后一行;a用来重复递加,以便读取下一行}
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
a:=0;{赋a值为0,以便按button1时读mylist的第一行}
if fileexists('E:\aa.txt') then
begin
mylist:=TString