#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    78
    Rep Power
    12

    Pass value from 1 class to another


    How can i pass the valure frim one class to another class??
    • CString tmpBuf;
      POSITION pos= m_OrderList.GetFirstSelectedItemPosition();
      int sel=m_OrderList.GetNextSelectedItem(pos);
      tmpBuf=m_OrderList.GetItemText(sel, 0);
      //GetDlgItem(IDC_ORDERNO)->SetWindowText(tmpBuf);

      tmpBuf=m_OrderList.GetItemText(sel, 1);
      tmpBuf.TrimRight();
      //GetDlgItem(IDC_DAY)->SetWindowText(tmpBuf);


    run-time error occur when i add the code below

    GetDlgItem(IDC_DAY)->SetWindowText(tmpBuf);

    How can i pass my value to the current class from where the IDC_ORDERNO control exists??
    Last edited by thcc; August 13th, 2003 at 02:20 AM.
    Programming is interesting
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    Does SetWindowText() take a CString? Maybe it takes a char * or maybe it takes a reference. Are you sure that you have a value in your tmpBuf (maybe it is NULL)? Try passing in something that you know is correct. What you are trying to do should cause no problems whatsoever. In fact you should be able to do this:

    Code:
    GetDlgItem(IDC_ORDERNO)->SetWindowText(m_OrderList.GetItemText(sel, 0));

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    78
    Rep Power
    12
    Run-time error still occur and the cursor go to the WINOCC.cpp file and stop at the linevoid CWnd::SetWindowText(LPCTSTR lpszString)
    {
    ASSERT(::IsWindow(m_hWnd));

    if (m_pCtrlSite == NULL)
    ::SetWindowText(m_hWnd, lpszString);
    else
    m_pCtrlSite->SetWindowText(lpszString);
    }
    Programming is interesting
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    78
    Rep Power
    12
    this is my code after the modification

    void OrderList::OnEdit()
    {
    CString tmpBuf;
    POSITION pos= m_OrderList.GetFirstSelectedItemPosition();
    int sel=m_OrderList.GetNextSelectedItem(pos);

    //tmpBuf=m_OrderList.GetItemText(sel, 0);
    //GetDlgItem(IDC_ORDERNO)->SetWindowText(tmpBuf);
    GetDlgItem(IDC_ORDERNO)->SetWindowText(m_OrderList.GetItemText(sel, 0));
    tmpBuf=m_OrderList.GetItemText(sel, 1);
    tmpBuf.TrimRight();
    //GetDlgItem(IDC_DAY)->SetWindowText(tmpBuf);

    // TODO: Add your control notification handler code here
    EndDialog(100);
    Order1 link_To_Order;
    link_To_Order.DoModal();
    }
    Programming is interesting
  8. #5
  9. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    So have you verified that tmpBuf has any data? Does it work for IDC_ORDERNO but not for IDC_DAY?

    Please enclose your code in "code" tags (see http://forums.devshed.com/misc.php?action=bbcode&s=).

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    78
    Rep Power
    12
    Code:
    void OrderList::OnEdit() 
    {
    	CString tmpBuf;
    	POSITION pos= m_OrderList.GetFirstSelectedItemPosition();
    	
    
    	int sel=m_OrderList.GetNextSelectedItem(pos);
        tmpBuf=m_OrderList.GetItemText(sel, 0);
    	AfxMessageBox(tmpBuf);
    	//GetDlgItem(IDC_ORDERNO)->SetWindowText(tmpBuf);
    	tmpBuf=m_OrderList.GetItemText(sel, 1);
    	tmpBuf.TrimRight();
    	//GetDlgItem(IDC_DAY)->SetWindowText(tmpBuf);
    	// TODO: Add your control notification handler code here
    	EndDialog(100);
    	Order1 link_To_Order;
    	link_To_Order.DoModal();
    }
    yap tempBuf returns my "Order No".

    Is it possible 4 me to send u the source code
    Can u pls help me!!!
    Last edited by thcc; August 13th, 2003 at 10:22 PM.
    Programming is interesting
  12. #7
  13. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    You would have to zip up the entire project (be sure to delete your 'Debug' and/or 'Release' directory!) along with any test data. I am not an expert at MFC but have done some work with it.

    Did you create IDC_DAY yourself or did the code generator do it for you? Can you get this to work?

    Code:
    GetDlgItem(IDC_DAY)->SetWindowText("Order No");
    You didn't say if it worked for IDC_ORDERNO.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    78
    Rep Power
    12
    hi,
    Thanks a lot, may i have your e-mail address??
    Last edited by thcc; August 14th, 2003 at 08:22 AM.
    Programming is interesting
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    78
    Rep Power
    12
    The code above cannot work because the IDC_DAY is the control ID frm different class.
    I really dun know how to do this cannot u pls help me
    Thanks
    Programming is interesting
  18. #10
  19. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    So what is the problem again? If IDC_DAY is from another class what is it doing in this class? You still haven't answered my question about IDC_ORDERNO, does it work?
    Last edited by mitakeet; October 15th, 2003 at 01:59 PM.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Malaysia
    Posts
    78
    Rep Power
    12
    The IDC_ORDERNO also cannot work, i still having problem with the value passing. I hope that u may help me.
    Pls refer to the Order1.cpp and the OrderList.cpp
    Thanks
    Last edited by thcc; August 14th, 2003 at 09:11 PM.
    Programming is interesting

IMN logo majestic logo threadwatch logo seochat tools logo