【例子介绍】文件文本逐行读取
通过listbox加载TXT逐行获取文本
【相关图片】
【源码结构】interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListView1: TListView;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
s: String;
i:Integer;
List: TStringList;
TempListItem:TListItem;
begin
List := TStringList.Create;
List.LoadFromFile('test.txt');
for i := 0 to List.Count - 1 do
begin
S := List[i];
TempListItem:=self.ListView1.Items.Add;
TempListItem.Caption:=S;
end;
List.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
TempListColumn:TListColumn;
begin
self.ListView1.ViewStyle:=vsReport;
TempListColumn:=self.ListView1.Columns.Add;
TempListColumn.Caption:='逐行显示文本';
TempListColumn.AutoSize:=true;
end;
end.
.
├── 5t6t网_文本文件的逐行读取.zip
└── 文本文件的逐行读取
├── Project1.cfg
├── Project1.dof
├── Project1.dpr
├── Project1.res
├── Unit1.dcu
├── Unit1.ddp
├── Unit1.dfm
├── Unit1.pas
├── Unit1.~ddp
├── Unit1.~dfm
├── Unit1.~pas
└── test.txt
1 directory, 13 files
评论