以下代码是根据条件,取数据库记录生成SPEEDBUTTON。希望对你有帮助。
var
MyB:array of TSpeedButton;
begin
Setlength(MyB,table1.RecordCount);
table1.First;
i:=0;
while not(table1.eof) do
begin
if table1.FieldByName('parent').asinteger=0 then
begin
MyB[I]:=TSpeedButton.Create(self);
MyB[I].Parent:=panel1;
{加入位置及宽高控制如:myb[i].width:=40;}
MyB[i].flat:=true;
MyB[i].caption:=trim(table1.fieldbyname('caption').asstring
Myb[i].onClick:=buttonclick;//按纽事件
i:=i+1;
end;
table1.next;
end;
end;