我想动态创建一个控件思路如下:
我在数据库中有一个列表字段如下:
01 美容师
02 美发师
03 助理师
这个我可以添加若干现在我有个动态界面和控件给这个字段关联
如:每一类 我要有一个 Panel Label combobx每一类可以自动创建一套这个内容的控件,panel的 是自动top label combox是居中的
我在用一个容器panel,让每一类的这一套控件排列在上面,如果有三类就排三套,如果增加自动增加,减少自动减少
如何实现较好,能有详细实现代码为感!!
我在数据库中有一个列表字段如下:
01 美容师
02 美发师
03 助理师
这个我可以添加若干现在我有个动态界面和控件给这个字段关联
如:每一类 我要有一个 Panel Label combobx每一类可以自动创建一套这个内容的控件,panel的 是自动top label combox是居中的
我在用一个容器panel,让每一类的这一套控件排列在上面,如果有三类就排三套,如果增加自动增加,减少自动减少
如何实现较好,能有详细实现代码为感!!
var ck:Tcheckbox;
//j:integer;
begin
dd.Date:=now()+1;
tt.Time:=strtotime('08:00:00');
with pub do
begin
close;
sql.Clear;
sql.Add('Select distinct mop_wkc_code From Tblworkcenterorder');
open;
end;
if pub.RecordCount>0 then //根據查詢的結果來創建checkbox控件數目
while not pub.Eof do
begin
ck:=Tcheckbox.Create(self); //創建控件
ck.Caption:=pub.FieldValues['mop_wkc_code']; //設置控件Caption屬性
ck.Parent:=Groupbox6; //為控件指定Parent
ck.Name:=copy(pub.FieldValues['mop_wkc_code'],1,3); //設置控件name屬性
if (pub.recno<4) then //給控件指定位置.
begin
ck.Top:=20;
ck.Left:=10+150*(pub.RecNo-1);
end;
if (pub.recno>=4) and (pub.recno<7) then
begin
ck.Top:=40;
ck.Left:=10+150*(pub.RecNo-4);
end;
if (pub.recno>=7) and (pub.recno<10) then
begin
ck.Top:=60;
ck.Left:=10+150*(pub.RecNo-7);
end;
if (pub.recno>=10) and (pub.recno<13) then
begin
ck.Top:=80;
ck.Left:=10+150*(pub.RecNo-10);
end;
if (pub.recno>=13) then
begin
ck.Top:=100;
ck.Left:=10+150*(pub.RecNo-13);
end;
ck.Width:=120;
ck.Height:=15;
pub.Next;
end;
listbox3.Clear;
with pub do
begin
close;
sql.Clear;
sql.Add('Select distinct mol_itm_code From renywip');
open;
end;
if pub.RecordCount>0 then
while not pub.Eof do
begin
listbox3.Items.Add(pub.FieldValues['mol_itm_code']);
pub.Next;
end;
end;