Class to Class data transfer
-
I have a class A, which is a dialog having a CEdit box with CString variable "m_Edit". I have another class B having a CString variable "str" declared in it. Now i want to make a call like this, CString str = m_Edit; This is to be done inside class B. How can i get the Edit box value in class A to class B CString "str". I tried a few things but couldn't make it work properly. Can anyone got any suggestions. Thanks in advance
-
I have a class A, which is a dialog having a CEdit box with CString variable "m_Edit". I have another class B having a CString variable "str" declared in it. Now i want to make a call like this, CString str = m_Edit; This is to be done inside class B. How can i get the Edit box value in class A to class B CString "str". I tried a few things but couldn't make it work properly. Can anyone got any suggestions. Thanks in advance
easiest way is to define a function in ClassB which accepts a pointer to a CEdit i.e
void CClassB::FixEdit(CEdit* pEdit)
Then in that function you can set the text to the string i.e.void CClassB::FixEdit(CEdit* pEdit) { pEdit->SetWindowText(m_str); }
How you call this up to you - but for example in the contructor of ClassA you could do the followingCEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT1); CClassB* cb = new CClassB(); cb->FixEdit(pEdit);
You could make the function static then you would not need to instantiate the CClassB but that's up to you - likewise you could create a function which would take a CEdit pointer and you could then read the contents of the Edit Box instead -
I have a class A, which is a dialog having a CEdit box with CString variable "m_Edit". I have another class B having a CString variable "str" declared in it. Now i want to make a call like this, CString str = m_Edit; This is to be done inside class B. How can i get the Edit box value in class A to class B CString "str". I tried a few things but couldn't make it work properly. Can anyone got any suggestions. Thanks in advance
I think your m_Edit variable declared as public. otherwise make it public. then you should create an object for class A, inside class B. Like this A objA; then do the assignment statement... CString str = objA.m_Edit; :cool: regards Vallikumar A