♣
简单问题,但我不会,高手帮忙~!!
怎么用字符串来调用控件?
比如说:
s:=edit;
有没有一种方法可以调用该字符串中的控件啊?
比如说我有十个同样的控件要进行同样的操作,
我用循环来实现,
i:integer;
s:string;
s:=edit;
for i:=1 to 10 do
begin
s:=s+inttostr(i);
访问(s).??
end;
大概意思就是这样的~!
能不能实现啊?
· 网友精彩回答:
用findcomponent即可
如:
var
i: integer;
s: string;
t: tcompent;
begin
s := edit;
for i := 1 to 10 do
begin
t := findcomponent(s + inttostr(i));
if (t <> nil) and (t is tedit) then
tedit(t).text := hello;
end;
end;
//沒有測試,不知道有沒有拼寫錯誤
同意楼上的
procedure tform1.button1click(sender: tobject);
var
i: integer;
begin
for i:= 1 to 3 do
begin
with tedit(findcomponent(edit+inttostr(i))) do
begin
text:= edit+inttostr(i);
end;
end;
end;
用list吧
var
mylist:tlist;
begin
mylist.add(tlabel.create(self)); //加入list
mylist.add(tedit.create(self));
for i := 0 to mylist.count-1 do
begin
if tcontrol(mylist.items[i]) is tlabel then
begin
mylist.items[i]).caption:= ;
end;
if tcontrol(mylist.items[i]) is tedit then......
end;
end;
//删除
tcontrol(mylist.items[i]).free;
mylist.delete(i);
//用着是方便,不过用起来也要小心。。。。呵呵
其实大家说的已经可以了,但是还有其他思路,比如公布公用方法,然后调用时传入参数即可
这个问题,csdn上都快问熟了,一搜一大把
procedure tform1.button1click(sender: tobject);
var i:integer;
begin
for i:=1 to 5 do tedit(self.findcomponent(edit+inttostr(i))).text:=inttostr(i);
end;
别忘了在窗体上放5个edit控件
- 更多问题:
- · 请问和CTabCtrl控件差不多,但是每个Tab都可以放置控件,点不同的Tab,显示不同的内容,这样的控件是什么呀
- · 今天特别想骂人,我一定要忍住,不骂人 不骂人
- · 求如下功能如何实现? 关于 IFRAME 框架的大小.
- · 局域网数据库连接的问题,本机可以连,其他机子连不上
- · 请教:DLL中显示对话框时所遇到的问题?
- · 请教,我这个tomcat怎么回事?!
- · DNS与BIND的配置
- · combobox与dataset绑定的一些问题?
- · 使用gprs手机上网问题
- · 请教关于稻香老农无组件上传的问题.
- · 学期期末作业,哪位达人帮忙~
- · 向TabCtrl控件发送消息时失败!
- · 计算不知道大小的数组大小的问题???!!!o(>_<)o!!!
- · 请教!如何获得对话框中属性页的句柄!
- · 如何进行远程连接访问数据库
- · 快疯了,动态分配的内存重叠

