Assign values to multiple edit boxes, given their names

旧街凉风 提交于 2020-01-03 20:57:19

问题


i am currently doing some programming in Borland C++ Builder 6.

I have 24 edit boxes(a visual component, with a text field) and i want to insert some values in the boxes, now i do it like this:

Edit1->Text=1;
Edit2->Text=2;
Edit3->Text=3;
...
Edit24->Text=24;

but i want to have something like this:

for(int i=1; i<25;i++){
Edit"i"->Text=i;
}

i think i have to make an array of objects or something. Can any body help me with this? I don't have a lot of experience with objects and stuff like that.


回答1:


There is a FindComponent function in VCL. It is used to find a component by it's name.

In your case it will look something like:

TEdit * tmp;
for( int i = 0; i < 24; i ++ )
{
    tmp = (TEdit*)MyForm->FindComponent("Edit" + IntToStr(i) );
    tmp->Text = i;
}


来源:https://stackoverflow.com/questions/11685195/assign-values-to-multiple-edit-boxes-given-their-names

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!