Solved

variable-Problem

Posted on 2000-02-29
7
191 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

860 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