我好郁闷呀。。。。。。。^<>^

North_beggar 2002-08-19 11:07:51
请教各位:application的用法。
一下是一个修改几个button.caption的小程序,为什么写成以下就可以
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to ComponentCount-1 do
begin
if Components[i] is Tedit then
Tedit(Components[i]).text:='Hello';
end;
end;
而写成以下就不行了呢?
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to Application.ComponentCount-1 do
begin
if Application..Components[i] is Tedit then
Tedit(Application.Components[i]).text:='Hello';
end;
end;
...全文
23 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
沧-海-桑-田 2002-08-19
  • 打赏
  • 举报
回复
来晚了.........
North_beggar 2002-08-19
  • 打赏
  • 举报
回复
谢谢各位,结贴。
dreamfan 2002-08-19
  • 打赏
  • 举报
回复
楼上讲的都很对
shuixin13 2002-08-19
  • 打赏
  • 举报
回复
application中是不包含Label的,
它只包含了Form,

而Label 是包含在Form中的,

所以
TForm.Components[I] 才可能找到Label,Text

呵呵,liuxiaowei(巍巍) ( 已讲得很清楚了
liuxiaowei 2002-08-19
  • 打赏
  • 举报
回复
application.components包含Form
form.components不包含Form本身
你改的是Form的components,用application的话这样写:
if application.components[i] is TForm then
begin
if (application.components[i] as TForm).Components[j] is TEdit
then
begin
((application.components[i] as TForm).Components[j] as TEdit).Caption := 'Text;'
end
end;
liuxiaowei 2002-08-19
  • 打赏
  • 举报
回复
application.components包含Form
form.components不包含Form本身
你改的是Form的components,用application的话这样写:
if application.components[i] is TForm then
begin
if application.components[i] as TForm).Components[j] is TEdit
then
begin
(application.components[i] as TForm).Components[j] as TEdit).Caption := 'Text;'
end
end;
North_beggar 2002-08-19
  • 打赏
  • 举报
回复
To liuxiaowei(巍巍):
请再说清楚点。只有一个窗体的application.components和form.components有区别吗?
liuxiaowei 2002-08-19
  • 打赏
  • 举报
回复
两个components不一样
第一个是TForm.Components
指form上的组件
第二个是TApplication.Components
指整个Application的组件!
快给分!

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧