Computer/C++
Child control 관리
Gu Youn
2003. 9. 15. 10:59
개념 : Form과 같은 parent control에는 ControlCount, Controls 프로퍼티가 있으며 이것을 이용해서 child control을 관리 할 수 있다.
controls : parent가 Form인 것들의 리스트
components : owner가 Form인 것들의 리스트
ClassName, ClassNameIs 함수를 이용하면 오브젝트의 타입 스트링을 얻을 수 있음.
소스 :
1. Controls 사용
//form 에 있는 control 개수 구하기
int max = StrToInt(Form1->ControlCount);
//control 개수 만큼 루프 돌면서 각 컨트롤의 tag 값 비교 및 초기화
for (int i=0;i<max;i++)
{
TControl *ChildControl = Form1->Controls[i];
int tag = ChildControl->Tag;
if(tag == 1)
{
(dynamic_cast<TLabel*>(ChildControl))->Caption = "a";
}
else
{
(dynamic_cast<TLabel*>(ChildControl))->Caption = "b";
}
}
2. Component 사용
int max = Form1->ComponentCount;
TComponent *ChildComponent;
for (int i=0; i<max ; i++)
{
ChildComponent = Form1->Components[i];
String ClassName = String(ChildComponent->ClassName());
}
controls : parent가 Form인 것들의 리스트
components : owner가 Form인 것들의 리스트
ClassName, ClassNameIs 함수를 이용하면 오브젝트의 타입 스트링을 얻을 수 있음.
소스 :
1. Controls 사용
//form 에 있는 control 개수 구하기
int max = StrToInt(Form1->ControlCount);
//control 개수 만큼 루프 돌면서 각 컨트롤의 tag 값 비교 및 초기화
for (int i=0;i<max;i++)
{
TControl *ChildControl = Form1->Controls[i];
int tag = ChildControl->Tag;
if(tag == 1)
{
(dynamic_cast<TLabel*>(ChildControl))->Caption = "a";
}
else
{
(dynamic_cast<TLabel*>(ChildControl))->Caption = "b";
}
}
2. Component 사용
int max = Form1->ComponentCount;
TComponent *ChildComponent;
for (int i=0; i<max ; i++)
{
ChildComponent = Form1->Components[i];
String ClassName = String(ChildComponent->ClassName());
}