We help IT Professionals succeed at work.

variable-Problem

BoogieBoy
BoogieBoy asked
on
209 Views
Last Modified: 2013-11-20
I have a dialog-based application, created with the assistent.
I added some member-functions. One of these functions returns the chosen value from a CCombo-box element by calling the CDialog-member-function

 CServiceInformatorDlg::GetDlgItemText(IDC_COMBO1,rProgname);

when I now create a new CServiceInformatorDlg e.g.newobject
and want to access the GetItem() function which wrapps the GetDlgItemText-function like
newobject.GetItem() NULL is returned.

Whats the problem with my code?

 void CServiceInformatorDlg::GetItem(CString &rProgname)
{
      
CServiceInformatorDlg::GetDlgItemText(IDC_COMBO1,rProgname);      
      MessageBox(dummy,NULL,MB_OK);
      
}


void CServiceInformatorDlg::OnButton1()
{
CString rock;
CServiceInformatorDlg test;
test.GetItem(rock);
}

Message Box stays empty
Comment
Watch Question

Commented:
You Should try this.

in the GetItem function.

CString Dummy;
GetDlgItemText(IDC_COMBO1, rProgName);
Dummy = rProgName
AfxMessageBox(Dummy);


in OnButtonFunction

CString rock;
GetItem(&rock);

Commented:
ooops in the GetItem Functions declaration put this

GetItem(CString* rProgName)
Top Expert 2007

Commented:
Well creating a new CServiceInformatorDlg in the OnButton1() doesn't in itself create a window of any type. In fact it just calls your dialog's constructor.

My question to you is... Do you just want to get the information from the combobox for the dialog you are currently processing? If so then just call GetItem(rock) like so:

void CServiceInformatorDlg::OnButton1()
{
CString rock;
GetItem(rock);
}

Good Luck,
Steve
Vinayak KumbarSr Program Manager

Commented:
HI,

Lot of confusions.....,

Why U want to use
>CServiceInformatorDlg::GetDlgItemText(IDC_COMBO1,rProgname);
in the same class?. Instead straight away use

GetDlgItemText(IDC_COMBO1,rProgname);

And here
>void CServiceInformatorDlg::OnButton1()
>{
>CString rock;
>CServiceInformatorDlg test;
>test.GetItem(rock);
>}

>CServiceInformatorDlg test; creates a new object of CServiceInformatorDlg  class. So test will be created by calling the constructor of the CServiceInformatorDlg class. I think U R inserting the strings to combo in the OnInitDialog function. But now U have not called that function yet. So Ur combo is empty. So U dont get anything. And Ur message box remains empty!!!.

Hope I explained U, the thing what u were doing.

VinExpert

Author

Commented:
Yes U r right.
Thats kind of useless to call a new CServiceInformatorDlg object. I am fillin Combo in OnInitDialog.

But the problem is located elsewhere: I have a new dialog CInfoDialog : CDialog and need the Combo data in there. So trying to call GetItem() member function of CServiceInformatorDlg doesnt work. I have to derive CInfoDialog from CServiceInformatorDlg and I dont know how to do this when I create a new dialog with the assistent  the assistent doesnt offer CServiceInformatorDlg as base-class. How do I teach it my base-class?

Is this the right anyway?

thanx for participating
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I dont get the point. I want to call GetItem from CInfo Dialog and implemented a membervariable and the memberfunction. But where in the code do I have to call GetItem() via the m_pSID variable?

When I call GetItem() via an BNClick event the programm terminates. Do I have to call it in the implementaion of CInfo Dialog::SetSID(..) and when yes, what is the parameter I have to call SetSID with?

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.