Solved

variable-Problem

Posted on 2000-02-29
7
193 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
0
Comment
Question by:BoogieBoy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Expert Comment

by:Stevex2
ID: 2569874
You Should try this.

in the GetItem function.

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


in OnButtonFunction

CString rock;
GetItem(&rock);

0
 

Expert Comment

by:Stevex2
ID: 2569894
ooops in the GetItem Functions declaration put this

GetItem(CString* rProgName)
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 2569923
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:VinExpert
ID: 2571343
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
0
 

Author Comment

by:BoogieBoy
ID: 2572909
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
0
 
LVL 3

Accepted Solution

by:
jsakhtar earned 50 total points
ID: 2594053
So which one are you trying to do?


Call GetItem() on a CServiceInformatorDlg from a CInfoDialog

or

Derive CInfoDialog from a CServiceInformatorDlg

To call GetItem() from a CInfoDialog, you need to provide the CInfoDialog with a pointer/reference to the CServiceInformatorDlg, then use that reference to call GetItem()

so make a member variable:

CServiceInformatorDlg* m_pSID;

And a member function

SetSID(CServiceInformatorDlg* pSID)
{
   m_pSID = pSID;
}

Then when you want to call GetItem from CInfoDialog use

CString str
m_pSID->GetItem(str)


To derive from a CServiceInformatorDlg create a new class derived from CDialog, then change all the words CDialog to CServiceInformatorDlg in the header and CPP files, and modify the constructor of CServiceInformatorDlg to take a UINT:

CServiceInformatorDlg (UINT nID, CWnd* pParent = NULL);   // standard constructor

Then in your derived class' constuctor
CInfoDialog::CInfoDialog(CWnd* pParent) :
CServiceInformatorDlg(CServiceInformatorDlg::IDD, pParent)  
0
 

Author Comment

by:BoogieBoy
ID: 2600149
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?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question