循环问题

xhwen 2008-04-03 09:26:49
我现在Form1上有30个Label1-Label30.我现在想在Form1一打开的时候就把表的table1和a字段刚好30行字符自动加载到Label1-Label30中去.这样的一个循环插入要怎么写?谢谢各位...
...全文
119 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
喝口水 2008-04-04
  • 打赏
  • 举报
回复
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
with adoquery1 do begin
Active:=true;
i:=0;
next;
for i:=0 toRecordCount do begin
TLabel(Form1.FindComponent('Label'+inttostr(i))).Caption:=FieldValues['x_a'];
next;
end;
end;
end;
kaikai_kk 2008-04-03
  • 打赏
  • 举报
回复
6楼的可以

Lbl1----Lbl30

procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
with Table1 do
begin
Active:=true;
First;
i:=1;
while i<=RecordCount-1 do
begin
TLabel(Form1.FindComponent('Lbl'+inttostr(i))).Caption:=FieldValues['FieldName'];
inc(i);
// if i=31 then
// exit
// else
next;
end;
end;
end;

dl110 2008-04-03
  • 打赏
  • 举报
回复
给你个动态的:

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
lb: array[0..29] of TLabel;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
i: byte;
begin
Table1.Active:=true;
for i:=0 to 29 do
lb[i].Free;
end;

procedure TForm1.FormShow(Sender: TObject);
var
i: byte;
begin
Table1.Active:=true;
for i:=0 to 29 do
begin
lb[i]:= TLabel.Create(nil);
lb[i].Parent:= Form1;
lb[i].Top:= 19+13*i;
lb[i].Left:= 80;
lb[i].Caption:= Table1.FieldValues['a'];
Table1.Next;
end;
end;

end.
GDTOPONE 2008-04-03
  • 打赏
  • 举报
回复

with adoquery1 do begin {这里要换成with Table1 do begin}
GDTOPONE 2008-04-03
  • 打赏
  • 举报
回复
不好意思,刚才一试以上代码发现有问题,以下可以全部显示正确了:

procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
with adoquery1 do begin
Active:=true;
i:=0;
next;
while i<=RecordCount do begin
TLabel(Form1.FindComponent('Label'+inttostr(i))).Caption:=FieldValues['x_a'];
inc(i);
next;
end;
end;
end;
喝口水 2008-04-03
  • 打赏
  • 举报
回复
还没来得及回答就上楼上的抢先了,哈,手好快呀
GDTOPONE 2008-04-03
  • 打赏
  • 举报
回复
修正一下:

procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
with Table1 do begin
Active:=true;
while RecNo<=30 do begin
TLabel(Form1.FindComponent('Label'+inttostr(RecNo))).Caption:=FieldValues['a'];
next;
end;

end;
end;

GDTOPONE 2008-04-03
  • 打赏
  • 举报
回复

procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
with Table1 do begin
Active:=true;
while RecNo<30 do begin
TLabel(Form1.FindComponent('Label'+inttostr(RecNo))).Caption:=FieldValues['a'];
next;
end;

end;
end;
xhwen 2008-04-03
  • 打赏
  • 举报
回复
对.我的表里面刚好有30行记录,所以想把a字段的30行分别第1行就加载到Label1,第2行就加载到Label2上一直到30行加载到Label1.
喝口水 2008-04-03
  • 打赏
  • 举报
回复
不太明白你的意思
我现在想在Form1一打开的时候就把表的table1和a字段刚好30行字符自动加载到Label1-Label30中去.
你的意思是要把表table1的a字段刚好30行记录自动加载到Label1-Label30中去吧,不知道意思理解错没

2,498

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧