Solved

variable-Problem

Posted on 2000-02-29
7
184 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now