|
이렇게 하면 되긴 되는데....
//---------------------------------------
void __fastcall TForm1::ShowEdit(TObject *Sender)
{
AnsiString conName = "Edit1";
AnsiString conName1 = "Edit2";
AnsiString conText;
char str[64];
sprintf(str,"1234");
TEdit *pEdit = NULL;
TEdit *pEdit1 = NULL;
TForm *pForm = (TForm *)((TButton *)Sender)->Parent;
for(int i=0; i<pForm->ControlCount; i++){
if(String(pForm->Controls[i]->ClassName()) == "TEdit"){
if(pForm->Controls[i]->Name == conName){
pEdit = (TEdit *)pForm->Controls[i];
}
else if(pForm->Controls[i]->Name == conName1){
pEdit1 = (TEdit *)pForm->Controls[i];
conText = pEdit1->Text.c_str();
}
}
}
pEdit->Text = conText;
}
//---------------------------------------
그리고 위 함수에서는 내가 접근할 콤포넌트의 이름을 알때 사용할수 있습니다...
쩡이 님이 쓰신 글 :
: 안녕하세요? 도움을 얻고자 질문을 올립니다.
: 하고자 하는 내용이..
: Form1, Form2... 등등, 복수의 폼에 공통적으로 표시할 내용을 하나의 함수로 만들고자 합니다.
: Form1에서 호출했으면 그 결과물을 Form1의 Edit에 뿌리고요, Form2에서 호출했으면 Form2에 뿌리고자 합니다.
: 그래서 호출한 Form의 인자를 얻어와야겠다고 생각했죠. (제대로 된 생각인지는 모르겠네요.. ㅡ0ㅡ;)
:
: void __fastcall TForm1::Button1Click(TObject *Sender)
: {
: Func->EditPrint(Sender); //함수호출, 버튼 인자를 넘기고
: }
:
: void __fastcall TFunc::EditPrint(TObject *Sender)
: {
: TButton *pButton= (TButton *) Sender; //호출한 버튼 알아내고
: TForm *pForm = (TForm *) pButton->Parent; //버튼의 부모인 폼을 알아내고
:
: pForm->Caption= IntToStr(1234);
: }
:
: 여기까지는 잘 됩니다. 그런데 문제가 되는 것이...
:
: void __fastcall TFunc::EditPrint(TObject *Sender)
: {
: TForm *pForm= ((TButton *) Sender)->Parent; //폼알아내기 한줄요약, 에러발생
: //에러내용 : E2034 - Cannot convert 'TWinControl * const' to 'TForm *'
:
: pForm->Edit1->Text= "1234"; //호출했던 폼의 Edit1에 출력, 에러발생
: //에러내용 : E2316 - 'Edit1' is not a member of 'TForm'
: }
:
: Edit1에 출력하는 것은 꼭 해야되는데요.. 힌트라도 주시면 감사하겠습니다.
: 행복하세요..
|