meipv wrote:
So, if m_object is a CString. X should also be of type CString? How do I
allow the lifetime of m_x to exceed x. Since m_object is from Dialog One is
there anything that I need to change in it or are all the changes made to
dialog TWO. Thanks so much for your help and replying.
Assume you have two modal dialog classes, Dlg1 and Dlg2, and you have a Dlg1
button handler as below:
void Dlg1::OnCallDlg2()
{
// More on cs below.
Dlg2 dlg2(cs);
if (dlg2.DoModal() == IDOK)
whatever;
}
The Dlg2 class looks something like this:
class Dlg2
{
public:
Dlg2(CString& cs)
: m_cs(cs)
{
}
private:
CString& m_cs;
};
Member functions in Dlg2 can modify the CString passed into its ctor through
the m_cs reference. (If you don't understand this, read up on "references".)
In this Dlg1::OnCallDlg2 line:
Dlg2 dlg2(cs);
The CString cs can be a local variable declared before dlg2, e.g.
CString cs;
cs.LoadString(IDS_WHATEVER);
Dlg2 dlg2(cs);
Or it can be a member variable of Dlg1. The important thing is that it's not
destroyed while Dlg2 is still using it, because Dlg2's m_cs reference member
is just another way of referring to cs.
--
Doug Harrison
Microsoft MVP - Visual C++