CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: assert problem

  1. #1
    Join Date
    Oct 1999
    Posts
    5

    assert problem

    Why does the program stop here?

    void CWnd::GetWindowText(Cstring& rString) const
    {
    XXX ASSERT(::IsWindow(m_hWnd));



    }

    void Hyrut::OnOK()
    {
    // TODO: Add extra validation here
    //UpdateData (TRUE);
    CTestSet Set;
    int hittad = 0;
    CString strText;
    XXX m_editBox.GetWindowText(strText);

    Set.m_strFilter = CString("KundId = ") + m_strKundId;
    Set.Open(CTestSet::snapshot, "Kund");
    Set.MoveFirst();

    while (!Set.IsEOF() && hittad == 0)
    {
    if(Set.m_Kund_KundId == strText)
    {
    Kunden Kund;
    Kund.DoModal();
    hittad = 1;
    }

    Set.MoveNext();

    if (hittad == 0)
    {

    MessageBox ("Kunden fanns ej");
    Registrera Regi;
    Regi.DoModal();
    }

    CDialog::OnOK();
    }

    }



  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: assert problem

    The ASSERT checked if m_editBox->m_hWnd is a window. It isn't, so the IsWindow() function returns FALSE, thereby triggering the Assertion failure. You can't set text in a non-valid window.

    Check your code to see how you initialized m_editBox, and to make sure that you are calling GetWindowText() when the window is valid (you can check this yourself by inspecting the m_editBox->m_hWnd value and verifying that the value is reasonable).

    Regards,

    Paul McKenzie


  3. #3
    Join Date
    Oct 1999
    Posts
    5

    Re: assert problem

    thanks for answering!!
    the m_editBox is a CEdit and we haven't initialized it in the constructor. Should we and with what value?
    we're using it like this:

    m_editBox.GetWindowText(m_strKundId);



    m_strKundId is connected to the editbox in our dialog.



  4. #4
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: assert problem

    > "m_strKundId is connected to the editbox in our dialog."

    If this is true (a CString member variable), then after UpdateData(TRUE) m_strKundId ALREADY contains the text in the edit box - you do not need to call GetWindowText().

    Where is m_editBox declared and first attached? The only way you can use a variable like this is (1) if you have declared it yourself and called SubclassDlgItem() during OnInitDialog() to attach it to an existing edit box, or (2) if you have used Class Wizard to add a member variable of type CEdit to an edit box at design time.

    If m_strKundId is a CString member variable mapped to the edit box, forget m_editBox - it is not needed.



    --
    Jason Teagle
    [email protected]

  5. #5
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    418

    Re: assert problem

    Hi Andre,

    m_editBox shouldn't be initialized in the constructor. It needs a valid window handle, and the dialog window (and with it the edit control) is created when the dialog class is in the OnInitDialog function. Initialize it in the DoDataExchange, which is called by the base implementation of OnInitDialog.

    Martin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured