CompuServe Thread

CEdit

8 messages in this thread
#30328From: Jay PerkinsJul 8, 1994 5:55 PM
I have created an object based off CEdit. I am currently using it in a Dialog Box that was created using App Wizard. I have added some static CString objects in "MyEdit" Object. Every time I try to add characters to a one of my Csting Objects my program Dies. It looks like my CString objects are not being properly allocated in memory. I'm not sure how to initialize an object (MyEdit) and its static Variables (CSting), that are being used in a Dialog Box. Can anyone Help????
#30390From: Charles SteinhardtJul 9, 1994 9:00 PM
Jay, I'd like to help but I'm slightly confused – can you send me a copy of your derived CEdit object? Speak with you soon, Charles Steinhardt[MVP], OMG Inc. Written 09-Jul-1994 @ 21:39:46 Windows NavCIS PRO 1.21 !^NavFont01F0007MGHHG64A747
#30411From: Jay PerkinsJul 10, 1994 11:02 AM
Here is the Header and CPP file of "MYEdit". class CFEdit : public CEdit { // Construction public: CFEdit(); CString Mask; //This is the Picture used to format the text CString Incoming; //This is the Typed (NUMBERS ONLY) characters CString CFEdit::Merge_Mask(CString raw,CString Picture); void Init(CString ivalue,CString mask); public: virtual ~CFEdit(); protected: //{{AFX_MSG(CFEdit) afx_msg UINT OnGetDlgCode(); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; This is the CPP File; #include "stdafx.h" #include "halstr.h" #include "fedit.h" //***************************************************************************** ************************* //****************************************************************************** ************************ //***************************************************************************** ************************* CFEdit::CFEdit() { } //***************************************************************************** ************************* //***************************************************************************** ************************* //****************************************************************************** ************************ CFEdit::~CFEdit() { } //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* BEGIN_MESSAGE_MAP(CFEdit, CEdit) //{{AFX_MSG_MAP(CFEdit) ON_WM_GETDLGCODE() ON_WM_KEYDOWN() ON_WM_CHAR() //}}AFX_MSG_MAP END_MESSAGE_MAP() //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* void CFEdit::Init(CString ivalue,CString mask) { this->SetWindowText(ivalue); Mask = mask; Incoming = ""; }; //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* UINT CFEdit::OnGetDlgCode() { return DLGC_WANTARROWS|DLGC_WANTALLKEYS|DLGC_WANTCHARS; }; //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* CString CFEdit::Merge_Mask(CString raw,CString Picture) { }; //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* afx_msg void CFEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if ((nChar >= '0') && (nChar <= '9')) { //****** "Incoming" is the CString that appears not Initialized!*************** Incoming += nChar; // <<===This is where It Dies!!!!! CString Temp = Merge_Mask(Incoming,Mask); this->SetWindowText(Temp); } else MessageBeep(0); } //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* void CFEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { CEdit::OnKeyDown(nChar, nRepCnt, nFlags); }; //***************************************************************************** ************************* //***************************************************************************** ************************* //****************************************************************************** ************************
#30417From: Charles SteinhardtJul 10, 1994 1:27 PM
Jay, I read ur message and I have a few comments. These comments will have "///////////////////////**CSS ….." prefacing them Here is the Header and CPP file of "MYEdit". //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* class CFEdit : public CEdit { // Construction public: CFEdit(); CString Mask; //This is the Picture used to format the text CString Incoming; //This is the Typed (NUMBERS ONLY) characters ///////////////////////**CSS Why do you have a class scope resolution here? CString CFEdit::Merge_Mask(CString raw,CString Picture); void Init(CString ivalue,CString mask); public: virtual ~CFEdit(); protected: //{{AFX_MSG(CFEdit) afx_msg UINT OnGetDlgCode(); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; This is the CPP File; #include "stdafx.h" #include "halstr.h" #include "fedit.h" //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* CFEdit::CFEdit() { } //***************************************************************************** ************************* //***************************************************************************** ************************* //****************************************************************************** ************************ CFEdit::~CFEdit() { } //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* BEGIN_MESSAGE_MAP(CFEdit, CEdit) //{{AFX_MSG_MAP(CFEdit) ON_WM_GETDLGCODE() ON_WM_KEYDOWN() ON_WM_CHAR() //}}AFX_MSG_MAP END_MESSAGE_MAP() //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* void CFEdit::Init(CString ivalue,CString mask) { ///////////////////////**CSS When does this ini function ever get called??? Did you mean to call this in the construtor? this->SetWindowText(ivalue); Mask = mask; ///////////////////////**CSS It doesn't die here, right? Incoming = ""; }; //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* UINT CFEdit::OnGetDlgCode() { return DLGC_WANTARROWS|DLGC_WANTALLKEYS|DLGC_WANTCHARS; }; //***************************************************************************** ************************* //***************************************************************************** ************************* //****************************************************************************** ************************ CString CFEdit::Merge_Mask(CString raw,CString Picture) { }; //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* ///////////////////////**CSS Get rid of "afx_msg" here afx_msg void CFEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if ((nChar >= '0') && (nChar <= '9')) { //****** "Incoming" is the CString that appears not Initialized!*************** ///////////////////////**CSS If you set a break point, what does "watch" (shift+F9) show regarding this "Incoming" CString? Incoming += nChar; // <<===This is where It Dies!!!!! CString Temp = Merge_Mask(Incoming,Mask); this->SetWindowText(Temp); } else MessageBeep(0); } //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* void CFEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { CEdit::OnKeyDown(nChar, nRepCnt, nFlags); }; //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* ///////////////////////**CSS My last question is, how and when do you define the CFEdit in your CDialog object? Speak with you soon, Charles Steinhardt OMG Inc.
#30422From: Jay PerkinsJul 10, 1994 3:46 PM
<<void CFEdit::Init(CString ivalue,CString mask) <<{ <<///////////////////////**CSS When does this ini function ever get called??? Did you mean to <<call this in the construtor? This function is called within the "Init_Dialog" section of my Dialog Window. I did this to ensure that my CStrings got initialized. <<///////////////////////**CSS It doesn't die here, right? << Incoming = ""; Yes, you are correct. It does die here when I call it from Dialog Window << //****** "Incoming" is the CString that appears not Initialized!*************** <<///////////////////////**CSS If you set a break point, what does "watch" (shift+F9) show <<regarding this "Incoming" CString? << Incoming += nChar; // <<===This is where It Dies!!!!! It Shows that "Incoming" = "" but it has reserved something like $1567 bytes of protected Memory. It always show "Incoming" = "" even if I initialize it in the constructor to something like "123".
#30435From: Charles SteinhardtJul 10, 1994 7:30 PM
O.K. – it really sounds o me as if you have more than one instance of CFEdit Last thing – send me your OnInitDialog function and send me teh decleration of how you implement the CFEdit in your dialog class. Speak with you soon, Charles Steinhardt[MVP], OMG Inc. Written 10-Jul-1994 @ 20:24:58 Windows NavCIS PRO 1.21 !^NavFont01F0007MGHHGB9B277
#30437From: Jay PerkinsJul 10, 1994 7:47 PM
Here is my OnInitDialog……… //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* BOOL CWptEdit::OnInitDialog() { CDialog::OnInitDialog(); CenterDialog(this); m_Jay_Edit.Init("N 00 00.000'","N ## ##.###'"); return TRUE; // return TRUE unless you set the focus to a control } Here is also part of my Header File for my dialog window……. class CWptEdit : public CDialog { // Construction public: CWptEdit(CWnd* pParent = NULL); // standard constructor // Dialog Data //{{AFX_DATA(CWptEdit) enum { IDD = IDD_WPT_EDIT }; CFEdit m_Jay_Edit; CButton m_Xte_Wpt; CButton m_Dest_Wpt; CButton m_Start_Wpt; CButton m_Enable_Wpt; CButton m_Position_Wpt; CEdit m_Name; CStatic m_EW_Ann; CStatic m_NS_Ann; CVBControl* m_Longitude; CVBControl* m_Latitude; CString Lat_Str; CString Lon_Str; BOOL North_Flg; BOOL West_Flg; CString m_Wpt_Name; BOOL IconFlg; BOOL Wpt_Enable_Flg; BOOL LL_Enable_Flg; BOOL Start_LL_Enable_Flg; BOOL Dest_LL_Enable_Flg; BOOL Xte_LL_Enable_Flg; //}}AFX_DATA Thanks so much for the Help!!!!!!!
#30443From: Charles SteinhardtJul 10, 1994 8:42 PM
Hi Jay, >> BOOL CWptEdit::OnInitDialog() { CDialog::OnInitDialog(); CenterDialog(this); m_Jay_Edit.Init("N 00 00.000'","N ## ##.###'"); return TRUE; // return TRUE unless you set the focus to a control } << I really want to help so pardon my asking 30 questions, but I'm unsure of what you are attempting to do. From my understanding, you said you had 1) an edit control derived from CEdit called CFEdit (I'm o.k. there) 2) that this edit control is used in your dialog 3) that you are crashing on a "+=" operator on a string (suggesting a problem with instance or CString memory) O.K. — but here is what I see. 1) You do have it defined as an embedded type in your class 2) you initialize this class – but how is it connected to your actual dialogs Edit control (the one created in AppStudio)? Where is your SubclassWindow or SubclassDlgItem API call for the Edit control in the dialog (that's how to hook up your derived control class to the actual edit control)?? Speak to you soon, Charles Steinhardt[MVP], OMG Inc. Written 10-Jul-1994 @ 21:39:34 Windows NavCIS PRO 1.21 !^NavFont01F0014MGHHGNMGPHGB2MGB4HJu46BD !); DDX_Control(pDX, IDC_START_WPT, m_Start_Wpt); DDX_Control(pDX, IDC_ENABLE_WPT, m_Enable_Wpt); DDX_Control(pDX, IDC_POSITION_WPT, m_Position_Wpt); DDX_Control(pDX, IDC_WPT_NAME, m_Name); DDX_Control(pDX, IDC_EW_ANN, m_EW_Ann); DDX_Control(pDX, IDC_NS_ANN, m_NS_Ann); DDX_VBControl(pDX, IDC_LONGITUDE, m_Longitude); DDX_VBControl(pDX, IDC_LATITUDE, m_Latitude); //}}AFX_DATA_MAP } //***************************************************************************** ************************* //***************************************************************************** ************************* //***************************************************************************** ************************* BEGIN_MESSAGE_MAP(CWptEdit, CDialog) //{{AFX_MSG_MAP(CWptEdit) ON_BN_CLICKED(IDC_SOUTH_BUT, OnClickedSouthBut) ON_BN_CLICKED(IDC_WEST_BUT, OnClickedWestBut) ON_BN_CLICKED(IDC_EAST_BUT, OnClickedEastBut) ON_BN_CLICKED(IDC_NORTH_BUT, OnClickedNorthBut) ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() Thanks Again……… Jay Perkins ///////////////////////////////////////////////////////////////////////////// // CWptEdit message handlers