delphi 数据按行滚动显示
有一个文本文件,如下形式:
a 1 e
b 2 f
c 3 g
d 4 h
e 5 i
如何实现其按行滚动显示在stringgrid中,一个cells中显示一个数。谢谢啦
[解决办法]
新建一个工程,双击窗体、将下列代码覆盖你的unit1
unit Unit1;
interface
uses
Windows, SysUtils, Classes, Controls, Forms,
StdCtrls, ExtCtrls, Grids;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure Timer1Timer(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var r:integer;
sl:array[0..2]of TStringList;
StringGrid1:TStringGrid;
Timer1: TTimer;
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
Height:=320;
Width:=420;
Position:=poScreenCenter;
OnCloseQuery:=FormCloseQuery;
for i:=0 to 2 do
sl[i]:=TStringList.Create;
for i:=0 to 4 do begin
sl[0].Append(char(i+ord('a')));
sl[1].Append(char(i+ord('1')));
sl[2].Append(char(i+ord('e')));
end;
for i:=5 to 7 do begin
sl[0].Append('');
sl[1].Append('');
sl[2].Append('');
end;
StringGrid1:=TStringGrid.Create(self);
with StringGrid1 do begin
RowCount:=8;
Parent:=Form1;
Width:=338;
Height:=210;
FixedCols:=0;
FixedRows:=0;
Left:=40;
Top:=30;
end;
Timer1:=TTimer.Create(self);
Timer1.OnTimer:=Timer1Timer;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var i,x:integer;
begin
for i:=0 to 7 do begin
x:=(r+i)mod 8;
StringGrid1.Cells[1,i]:=sl[0][x];
StringGrid1.Cells[2,i]:=sl[1][x];
StringGrid1.Cells[3,i]:=sl[2][x];
end;
//滚上:
inc(r);
{
//滚下:
r:=r+8;
dec(r);
}
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var i:integer;
begin
Timer1.Enabled:=false;
Timer1.Free;
StringGrid1.Free;
for i:=0 to 2 do sl[i].Free;
end;
end.