动态创建控件!(200分)

  • 主题发起人 主题发起人 forall
  • 开始时间 开始时间
F

forall

Unregistered / Unconfirmed
GUEST, unregistred user!
要求:<br>一个combox,里面有1,2,3,4,5,6<br>如果选择1那么显示一行:<br>label11 dbedit11 &nbsp;dbedit12 &nbsp;dbedit13<br><br>如果选择2那么显示两行:<br>label11 dbedit11 &nbsp;dbedit12 &nbsp;dbedit13<br>label21 dbedit21 &nbsp;dbedit22 &nbsp;dbedit23<br><br>以此类推,填写dbedit后,button提交.<br><br>显示的时候如果一行dbedit都没有内容或者是零就隐藏,combox里面显示行数,大概就这个意思.
 
那些edit里的数据哪来的? 数据库?<br><br>type<br>&nbsp; TEditList=array of TObject;<br><br>...<br><br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; edtlists:array of TEditList;<br>&nbsp; &nbsp; procedure clearedtlists;<br><br>...<br><br>procedure TForm1.clearedtlists;<br>var<br>&nbsp; i:integer;<br>begin<br>&nbsp; for i:=0 to length(edtlists)-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; TLabel(edtlists[0]).Free;<br>&nbsp; &nbsp; TEdit(edtlists[1]).Free;<br>&nbsp; &nbsp; TEdit(edtlists[2]).Free;<br>&nbsp; &nbsp; TEdit(edtlists[3]).Free;<br>&nbsp; &nbsp; setlength(edtlists,0);<br>&nbsp; end;<br>&nbsp; setlength(edtlists,0);<br>end;<br><br>procedure TForm1.ComboBox1Select(Sender: TObject);<br>var<br>&nbsp; i,x,<br>&nbsp; t,l:integer; {这两个控制显示位置,自己改}<br>begin<br>&nbsp; clearedtlists;<br>&nbsp; x:=combobox1.ItemIndex+1; {获得显示的行数,我默认combobox里行数和数字是对应的}<br>&nbsp; setlength(edtlists,x);<br>&nbsp; t:=10;<br>&nbsp; for i:=0 to x-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; l:=10;<br>&nbsp; &nbsp; setlength(edtlists,4);<br>&nbsp; &nbsp; edtlists[0]:=TLabel.Create(self);<br>&nbsp; &nbsp; with TLabel(edtlists[0]) do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Parent:=self;<br>&nbsp; &nbsp; &nbsp; Caption:='Label'+inttostr(i);<br>&nbsp; &nbsp; &nbsp; SetBounds(l,t,100,13);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; inc(l,100+10); {控件间隔10像素}<br>&nbsp; &nbsp; edtlists[1]:=TEdit.Create(self);<br>&nbsp; &nbsp; with TEdit(edtlists[1]) do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Parent:=self;<br>&nbsp; &nbsp; &nbsp; Text:=inttostr(i)+',0'; {省事按edit处理了,自己修改成读数据库数据}<br>&nbsp; &nbsp; &nbsp; SetBounds(l,t,100,21);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; inc(l,100+10); {控件间隔10像素}<br>&nbsp; &nbsp; edtlists[2]:=TEdit.Create(self);<br>&nbsp; &nbsp; with TEdit(edtlists[2]) do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Parent:=self;<br>&nbsp; &nbsp; &nbsp; Text:=inttostr(i)+',1'; {省事按edit处理了,自己修改成读数据库数据}<br>&nbsp; &nbsp; &nbsp; SetBounds(l,t,100,21);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; inc(l,100+10); {控件间隔10像素}<br>&nbsp; &nbsp; edtlists[3]:=TEdit.Create(self);<br>&nbsp; &nbsp; with TEdit(edtlists[3]) do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Parent:=self;<br>&nbsp; &nbsp; &nbsp; Text:=inttostr(i)+',2'; {省事按edit处理了,自己修改成读数据库数据}<br>&nbsp; &nbsp; &nbsp; SetBounds(l,t,100,21);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; inc(t,30); {行间隔30像素}<br>&nbsp; end;<br>end;
 
楼上只写了一半,显示的时候也要有多少数据显示多少行
 
显示的时候? 你的行数不是从combobox里得到的吗?
 
后退
顶部