Edit-Feld-> Ich bekomm den String da nicht raus, warum?
-
Hallo.
Ich hab ein eigentlich einfaches Problem:
void CDlgRouteConfig::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Text (pDX, IDC_EDIT_ROUTE , m_strAddRoute); } void CDlgRouteConfig::OnBnClickedButtonAddRoute() { m_strAddRoute = _T(""); GetDlgItem(IDC_EDIT_ROUTE)->UpdateData(TRUE); if(m_strAddRoute == _T("")) { return; // Wo ist mein String geblieben?????? } // Dann weiteres }Tja, nur leider kommt der String aus den Edit-Feld (IDC_EDIT_ROUTE) nie im CString-Objekt m_strAddRoute an und ich returne sofort wieder. Habs auch schon mit UpdateData(FALSE) probiert (Ich weiß, ist Blödsinn), keine Besserung. Und ja, das Edit-Feld enthält zu dem Zeitpunkt auch einen gültigen String.
Danke für jede Hilfe.
-
void CDlgRouteConfig::OnBnClickedButtonAddRoute() { UpdateData(true); // ..... }Reicht aus, da du ja bereits den Control mit deiner Variablen verknüpft hast.
-
Ich hab das so gemacht, weil ich UpdateData nur auf das Editfeld haben wollte.
Ich hab eigentlich noch viele, viele andere Ctrl's auf meinen Dlg.
-
UpdateData auf einzelne Steuerelemente ist Blödsinn, weil die selbst keine DoDataExchange-Methode haben, die irgendwas tut.
Benutz GetDlgItemText, wenn du nicht alles auf einmal aktualisieren willst.
-
Wenn du einen Control alleine abfrage willst, mache es doch so:
void CDlgRouteConfig::OnBnClickedButtonAddRoute() { GetDlgItem(IDC_EDIT_ROUTE)->GetWindowText(m_strAddRoute); if(m_strAddRoute == _T("")) { return; // Wo ist mein String geblieben?????? } // Dann weiteres }
-
My view is, if you are writing more than one GetDlgItem per year, you are probably not using C++/MFC correctly. Fortunately, there is a better, more elegant, and safer way to get access to controls using MFC.
http://www.flounder.com/getdlgitem.htm
Microsoft does not adequately document the correct way to work with controls. It is left up to the programmer to somehow magically infer the correct way to do this. Unfortunately, all of the evidence suggests that UpdateData is the correct way to handle the problem of accessing control information while working inside a dialog. This is not correct. In fact, it is dangerous to use it. It is simply the wrong way to go about it.