遍历所有Edit组件,如何使符合条件的Edit组件改变属性

luanshiguzhu 2015-04-09 09:28:23
AnsiString str= "Edit2" ;

for(int i=0;i<this->ComponentCount;i++)
{

if(this->Components[i]->Name==str)
{

ShowMessage( (this->Components[i])->Name );

(TEdit(Form1->Components[i])).Text="1243";//这可以编译
(TEdit(Form1->Components[i]))->Text="1243";//编译显示错误,但不知道错在哪儿了?
(TEdit(Form1->Components[i]))->Color=clSkyBlue;//编译显示错误,但不知道错在哪儿了?
}

}
...全文
163 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccrun.com 2015-04-09
  • 打赏
  • 举报
回复
AnsiString str=  "Edit2" ;
for (int i = 0; i < ComponentCount; i++)
{
if (Components[i]->Name == str)
{
TEdit *edt = (TEdit *)Components[i];
if (edt)
{
edt->Text = "1243";
edt->Color = clSkyBlue;
}
}
}
luanshiguzhu 2015-04-09
  • 打赏
  • 举报
回复
我按照你的方法,改了之后编译提示[C++ Error] Unit1.cpp(63): E2108 Improper use of typedef 'TEdit'
draculamx 2015-04-09
  • 打赏
  • 举报
回复
把 (TEdit(Form1->Components[i])) 改成 (TEdit *(Form1->Components[i]))

604

社区成员

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

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