如何得到自動生成的組件的一些屬性. ( 积分: 40 )

  • 主题发起人 主题发起人 Jj1985
  • 开始时间 开始时间
J

Jj1985

Unregistered / Unconfirmed
GUEST, unregistred user!
我查詢一數據庫後.
在窗口上動態生成了一些組件:
while not adoquery1.eof do
begin
ss:=Tbsskincheckradiobox.Create(application);
ss.Parent:=box;
ss.Name:='chick'+inttostr(adoquery1.RecNo);
ss.caption:=adoquery1.fieldbyname('name').asstring;
ss.Left:=200;
ss.Top:=30+25*adoquery1.RecNo;
ss.SkinData:=mainskindata;
adoquery1.Next;
end;
現有一按鈕.!單擊它後把上面自動生成的組件中checked為True的Caption顯示出來.!
for i:=0 to form12.ControlCount-1 do
begin
if (form12.Controls is Tbsskincheckradiobox ) then
begin
if (form12.Controls as Tbsskincheckradiobox).Checked then
begin
s:=(form12.Controls as Tbsskincheckradiobox).caption;
showmessage(s);
end;
end;
end; 這段沒反映.!
for i:=1 to adoquery1.RecordCount do
begin
if Tbsskincheckradiobox(findcomponent('chick'+inttostr(i))).Checked then
s:=s+Tbsskincheckradiobox(findcomponent('chick'+inttostr(i))).Caption;
end; 這段報錯.!
請高手幫忙寫出來.
 
for i:=1 to adoquery1.RecordCount do
begin
if Tbsskincheckradiobox(findcomponent('chick'+inttostr(i))).Checked then
s:=s+Tbsskincheckradiobox(findcomponent('chick'+inttostr(i))).Caption;
end; 這段報錯.!

for I := 0 to adoquery1.RecordCount - 1 do

var
AComponent: TComponent;
I: Integer;
S: string;
begin
for I := 0 to AdoQuery1.RecordCount - 1 do
begin
AComponent := FindComponent('chick'+inttostr(i));
if AComponent is Tbsskincheckradiobox then
with Tbsskincheckradiobox(AComponent) do
if Checked then S := S + Caption;
end;
end;
 
還是沒有反映.!
顯示出來的S是一空串.!
 
数据库里没数据
adoquery1.fieldbyname('name').asstring 为空
 
后退
顶部