我想在 Delphi 7 的运行时从表中创建组件(面板),但仅在字段值 > 0 时创建。
示例:
widht |p1|p2|p3|p4|p5|p6|p7|.. |像素|
1500 | 5 | 5 | 5 | 0 | 0 | 0 | 0 |..|0 | // 创建 3 个面板
2700 | 5 | 5 | 5 | 6 | 6 | 0 | 0 |..|0 | // 创建 5 个面板
....
private
{ Private declarations }
pn : array of TPanel;
..................................
procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
oldpn: TComponent;
begin
table1.SetKey;
table1.FindNearest([form2.Edit2.Text]);
i:= table1.FieldCount;
SetLength(pn, i);
for i:= 1 to i-1 do
begin
oldpn:= Findcomponent('pn'+inttostr(i));
oldpn.Free;
pn[i]:= TPanel.Create(form1);
pn[i].Parent := form1;
pn[i].Caption := 'Panel' + inttostr(i);
pn[i].Name := 'pn'+inttostr(i);
pn[i].Height := table1.Fields[i].Value ;
pn[i].Width := 500;
pn[i].Color:=clGreen;
pn[1].Top := form1.ClientHeight - pn[1].Height;
if (i > 1) then pn[i].Top := pn[i-1].Top - pn[i].Height;
pn[i].OnClick := pnClick;
end;
end;
此代码为我创建了面板,但适用于所有字段。我希望能够仅从值 > 0 的字段中声明“pn”数组...
我尝试过:
如果 table1.Fields[i].Value > 0 然后
开始
i:= table1.FieldCount....
但是它不起作用。任何想法?提前致谢!