标题:动态生成问题~
只看楼主
zhansong333
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2006-4-4
 问题点数:0 回复次数:1 
动态生成问题~

procedure TForm1.Button1Click(Sender: TObject); //在生成 query1.recordcount个单选框
var pn:tradiogroup;
count1,j:integer;
begin
query1.Close;
query1.SQL.Clear;
query1.sql.Add('select * from 备用题库');
query1.ExecSQL;
query1.Active:=true;
count1:=query1.recordcount;

for j:=0 to count1 do
begin
pn:=tradiogroup.Create(scrollbox1);
pn.Parent:=scrollbox1;
pn.Left:=24;
pn.Width:=249;
pn.Height:=121;
pn.Top:=(j+1)*121+2;
end;
end;

procedure TForm1.Button2Click(Sender: TObject); //显示题目
var index,k:integer;
begin
k:=0;
for Index:=0 to scrollbox1.ControlCount-1 do
begin
query1.first;
query1.moveby(k);
if Components[Index] is TRadiogroup then
with (Components[Index] As TRadiogroup) do
begin
caption:=query1.FieldByName('题干').Asstring;
items.Add(query1.FieldByName('选项A').Asstring);
items.Add(query1.FieldByName('选项B').Asstring);
items.Add(query1.FieldByName('选项C').Asstring);
k:=k+1;
end;
end;
end;
可为什么最后显示题目时候,只有radiogroup1内显示题目内容呢? 动态生成的都没显示。 请指教

搜索更多相关主题的帖子: 动态 
2006-05-08 10:07
zhansong333
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2006-4-4
得分:0 
已被解答!!!


if Components[Index] is TRadiogroup then
//是错的,直接写 Components[Index] 默认成form的component了!

应该把 Components[Index] 改成
scrollbox1.Controls[Index]

xiexie!!!!!!!!
2006-05-09 09:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-62500-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.025850 second(s), 10 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved