-
pass variable value from one dialogbox to other/ one class to other class in vc++ MFC
hello,
I am trying to pass variable of one class to other class, i did this by calling that doalogbox using DoModal method . But it give retry,Abort,ignore type of messagebox/ Exception.
Is there any way to access variable of one class to other class.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Is there any way to access variable of one class to other class.
Class A provides a get() method, Class B provides a set() method. If anything more is needed, then details of the classes involved would be helpful.
If Class B is derived from Class A and the variable needs to be private in A, then consider making it protected so B can access it but it still remains private outside of the classes.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Originally Posted by
2kaud
Class A provides a get() method, Class B provides a set() method. If anything more is needed, then details of the classes involved would be helpful.
If Class B is derived from Class A and the variable needs to be private in A, then consider making it protected so B can access it but it still remains private outside of the classes.
if they are not reletaed by inheritance ?
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
if they are not reletaed by inheritance ?
if we able do this unless they are not related by inheritance means they are independent class then how to do this. means have we need to create a object of class and call get method?
plz give one example. Thanx for quick reply
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
hello,
I am trying to pass variable of one class to other class, i did this by calling that doalogbox using DoModal method . But it give retry,Abort,ignore type of messagebox/ Exception.
Is there any way to access variable of one class to other class.
http://forums.codeguru.com/showthrea...se-Versa-in-VC
http://forums.codeguru.com/showthrea...tbox-to-Dialog
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
hello,
I am trying to pass variable of one class to other class, i did this by calling that doalogbox using DoModal method . But it give retry,Abort,ignore type of messagebox/ Exception.
Is there any way to access variable of one class to other class.
You may also want to read this excellent J.Newcomer's essay about Dialog and Control Design as well as a lot of his other useful articles: http://www.flounder.com/mvp_tips.htm#Dialog Box Series
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
plz give one example. Thanx for quick reply
Consider this very simple example
Code:
#include <iostream>
#include <string>
using namespace std;
template<typename T>
class A {
private:
T pa;
public:
A(T a) : pa(a) {}
T geta() const {
return pa;
}
void seta(const T& a) {
pa = a;
}
};
template<typename T>
class B {
private:
T pb;
public:
B(T b) : pb(b) {}
T getb() const {
return pb;
}
void setb(const T& b) {
pb = b;
}
};
int main()
{
A<string> a("This is A"s);
B<string> b("This is B"s);
cout << "a = " << a.geta() << ", b = " << b.getb() << endl;
b.setb(a.geta());
cout << "a = " << a.geta() << ", b = " << b.getb() << endl;
}
This displays
Code:
a = This is A, b = This is B
a = This is A, b = This is A
as the private variable of B has been set to that of A.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Originally Posted by
VictorN
There is no inheretance no parent class.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Quote:
Originally Posted by
VictorN
There is no inheretance no parent class.
Well it was the reply to your original question where you asked nothing about "inheretance":
Quote:
hello,
I am trying to pass variable of one class to other class, i did this by calling that doalogbox using DoModal method . But it give retry,Abort,ignore type of messagebox/ Exception.
Is there any way to access variable of one class to other class.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
There's nothing magic about dialog boxes. You pass variables around the same way you do with any other objects. You can write set and get methods or if it's public, just set the member directly.
CMyDialog dlg;
dlg.m_intVariable = 7;
What's the confusion?
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Originally Posted by
GCDEF
There's nothing magic about dialog boxes. You pass variables around the same way you do with any other objects. You can write set and get methods or if it's public, just set the member directly.
CMyDialog dlg;
dlg.m_intVariable = 7;
What's the confusion?
in CMyDialog1 class file:
m_intVariable =7;
and in CMyDialog2 class file:
int value;
CMyDialog1 dlg;
value= dlg.m_intVariable ;
if we do not call DoModal method before assignment then dlg.m_intVariable is empty.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Originally Posted by
2kaud
Consider this very simple example
Code:
#include <iostream>
#include <string>
using namespace std;
template<typename T>
class A {
private:
T pa;
public:
A(T a) : pa(a) {}
T geta() const {
return pa;
}
void seta(const T& a) {
pa = a;
}
};
template<typename T>
class B {
private:
T pb;
public:
B(T b) : pb(b) {}
T getb() const {
return pb;
}
void setb(const T& b) {
pb = b;
}
};
int main()
{
A<string> a("This is A"s);
B<string> b("This is B"s);
cout << "a = " << a.geta() << ", b = " << b.getb() << endl;
b.setb(a.geta());
cout << "a = " << a.geta() << ", b = " << b.getb() << endl;
}
This displays
Code:
a = This is A, b = This is B
a = This is A, b = This is A
as the private variable of B has been set to that of A.
I want to perfom as I asked my previous question how to get text of selected item in list control
1] Select one iteam in list control
2] store it into variable
3] access that variable with it's containing value into other class (which I have to pass to SQLquery in code )
now just want to know that how pass that value and get into other class ?
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
1) and 2) have already been discussed in your other thread.
For 3), for the class that stores the text variable, provide a get method to return the value. For the other class access the value via this get method. If this can't be done, then further details of the classes would be useful.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Code:
void Cselect_product::OnItemchangedListCategory(NMHDR* pNMHDR, LRESULT* pResult)
{
POSITION pos = m_klist.GetFirstSelectedItemPosition();
if (pos == NULL)
TRACE0("No items were selected! \n");
else
while (pos)
{
int nItem = m_klist.GetNextSelectedItem(pos);
TRACE1("Item %d was selected! \n", nItem);
//you could do your own processing on nItem here
strText = m_klist.GetItemText(nItem, 0);
//Update the edit control with this value ??
}
*pResult = 0;
}
From the other thread, this is the code to get the value of the selected item(s). Rather than just store the value in strText (which doesn't seem right if multiple items are selected?), don't you need to have code here that updates your edit control with the value??
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Originally Posted by
2kaud
1) and 2) have already been discussed in your other thread.
For 3), for the class that stores the text variable, provide a get method to return the value. For the other class access the value via this get method. If this can't be done, then further details of the classes would be useful.
in CMyDialog1 class file:
m_intVariable =7;
and in CMyDialog2 class file:
int value;
CMyDialog1 dlg;
value= dlg.m_intVariable ;
if we do not call DoModal method before assignment then dlg.m_intVariable is empty.
please give me simple solution for this.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
in CMyDialog1 class file:
m_intVariable =7;
and in CMyDialog2 class file:
int value;
CMyDialog1 dlg;
value= dlg.m_intVariable ;
if we do not call DoModal method before assignment then dlg.m_intVariable is empty.
please give me simple solution for this.
I did not get that class example
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
in CMyDialog1 class file:
m_intVariable =7;
and in CMyDialog2 class file:
int value;
CMyDialog1 dlg;
value= dlg.m_intVariable ;
if we do not call DoModal method before assignment then dlg.m_intVariable is empty.
please give me simple solution for this.
Please, read the http://www.flounder.com/dlgctl.htm
You will find the solution there.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Originally Posted by
VictorN
I tried but not able to implement. Please It will be great-full if some one send me small project zip for following task.
1]I want to set one value to the variable on Dialogbox1 class file.
2] I want to access that value on second dialogbox, without showing that dialogbox.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
I tried but not able to implement. Please It will be great-full if some one send me small project zip for following task.
1]I want to set one value to the variable on Dialogbox1 class file.
2] I want to access that value on second dialogbox, without showing that dialogbox.
Just look at the post#10!
You have to create a member variable in your dialog class (say it is a CMyDialog class, so use class Wizard and create the variable, say it is int m_intVariable)
Then you write to set the variable:
Code:
CMyDialog dlg;
dlg.m_intVariable = 7;
Now you can call the DoModal to let the user interact with your dialog and after dialog will be closed you'll be able to get (probably, changed value of m_intVariable back:
Code:
CMyDialog dlg;
dlg.m_intVariable = 7;
if(dlg.DoModal() == IDOK)
{
int newValue = dlg.m_intVariable;
}
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Originally Posted by
VictorN
Just look at the post#10!
You have to create a member variable in your dialog class (say it is a CMyDialog class, so use class Wizard and create the variable, say it is
int m_intVariable)
Then you write to set the variable:
Code:
CMyDialog dlg;
dlg.m_intVariable = 7;
Now you can call the
DoModal to let the user interact with your dialog and after dialog will be closed you'll be able to get (probably, changed value of
m_intVariable back:
Code:
CMyDialog dlg;
dlg.m_intVariable = 7;
if(dlg.DoModal() == IDOK)
{
int newValue = dlg.m_intVariable;
}
User breakpoint called from code at 0x758248be error showing after calling DoModal.
This is third Dialogbox which I opened, periviously two dialogbox already opened.
Mens 1 Main Dialogbox1 then I called second dialogbox2 using DoModal Method. And this is Third Dialogbox3 which I called.
Is this error because of this?
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
User breakpoint called from code at 0x758248be error showing after calling DoModal.
Sounds that something is wrong in your "third Dialogbox" class implementation!
Quote:
Mens 1 Main Dialogbox1 then I called second dialogbox2 using DoModal Method. And this is Third Dialogbox3 which I called.
Is this error because of this?
No. See above.
What is the exact error message you see? Note that you can just press Ctrl+C to copy the whole content of the dialog box message and then post it to the Forum.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
User breakpoint called from code at 0x758248be error showing after calling DoModal.
This is third Dialogbox which I opened, periviously two dialogbox already opened.
Mens 1 Main Dialogbox1 then I called second dialogbox2 using DoModal Method. And this is Third Dialogbox3 which I called.
Is this error because of this?
No telling what's wrong from that description. Time to use your debugger to find out. It should be taking you to the error when it occurs.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
I tried but not able to implement. Please It will be great-full if some one send me small project zip for following task.
1]I want to set one value to the variable on Dialogbox1 class file.
2] I want to access that value on second dialogbox, without showing that dialogbox
comletely wrong unless you mean static variables
Instead of trying to acces private variables of another class
better try to obtain current object of that class and invoke it's(public) functons
//CClass.cpp
...
//Main.cpp global scope ,CClass.h included
CClass cl;
...
//CClassZ.cpp
#include "CClass.h"
extern CClass cl;
CClassZ::Somestuff()
{
cl.whatsoever
}
BUT you cant do it this way with MFC dialogs(coz CDialog-derived constructor does need intra-instance stuff and fails at global scope)
so..
//CDialClass.cpp
...
//Main.cpp global scope ,CDialClass.h included
HWND hd;
CDialApp::InitInstance()
{
CDialClass cl;
...
//after cl window is created somehow
hd=cl.m_hWnd;
//you can do this also inside CDialClass ithelf with hd=this->m_hWnd;
}
...
//CDialClassZ.cpp
#include "CDialClass.h"
extern HWND hd;
CDialClassZ::Somestuff()
{
//hard
((CDialClass *)CDialog::FromHandle(hd))->whatsoever;
}
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Originally Posted by
Alexeyn
comletely wrong unless you mean static variables
Instead of trying to acces private variables of another class
better try to obtain current object of that class and invoke it's(public) functons
There's really no need to bump old threads with answers that don't make sense or have nothing to do with the original question.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Really?
You all just cant answer
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Originally Posted by
Alexeyn
Really?
You all just cant answer
Did you read the thread? His question was answered by several of us.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Originally Posted by
Alexeyn
comletely wrong unless you mean static variables
Instead of trying to acces private variables of another class
better try to obtain current object of that class and invoke it's(public) functons
//CClass.cpp
...
//Main.cpp global scope ,CClass.h included
CClass cl;
Next time when you will be going to answer... please, read the Announcement: Before you post...., particularly the section about code tags.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Originally Posted by
Alexeyn
comletely wrong unless you mean static variables
Instead of trying to acces private variables of another class
better try to obtain current object of that class and invoke it's(public) functons
//CClass.cpp
...
//Main.cpp global scope ,CClass.h included
CClass cl;
...
//CClassZ.cpp
#include "CClass.h"
extern CClass cl;
CClassZ::Somestuff()
{
cl.whatsoever
}
BUT you cant do it this way with MFC dialogs(coz CDialog-derived constructor does need intra-instance stuff and fails at global scope)
so..
//CDialClass.cpp
...
//Main.cpp global scope ,CDialClass.h included
HWND hd;
CDialApp::InitInstance()
{
CDialClass cl;
...
//after cl window is created somehow
hd=cl.m_hWnd;
//you can do this also inside CDialClass ithelf with hd=this->m_hWnd;
}
...
//CDialClassZ.cpp
#include "CDialClass.h"
extern HWND hd;
CClassZ::Somestuff()
{
//hard
((CDialClass *)CDialog::FromHandle(hd))->whatsoever;
}
The more you add the worse it gets. I really can't even tell what you're trying to say here, how it helps the OP, or how it's an improvement over the previous answers.
-
Re: pass variable value from one dialogbox to other/ one class to other class in vc++
Quote:
Originally Posted by
Alexeyn
Really?
You all just cant answer
Neither you could. The real problem of OP is being unable to explain what he really wants. And answer to question that sounds gibberish is initially prone to sound gibberish. Exactly like your answer does.