How to do this in C++ Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

How to do this in C++

Post by Hossein » Wed Dec 09, 2009 4:17 pm

hello all , sorry for bad topic , i didnt know what else to choose .
here is my problem :
im going to make a set{} function to communicate between forms
im C# i would write :

Code: Select all

public string SetText
{
   
   set{ textBox.Text = value;} 
}
but in C++, i encountered some problem ,
i wrote
(suppose i have a textbox in my frmOpetion, called TextCtrl1 , and im placing this bit of code in my frmOption.h

Code: Select all

void SetText(String Text)
{
     TextCtrl1.text = Text;//i dont know what to write here exactly!  i mean the wxwigets way! 
   
}
to be precise my frmOption.h looks like this

Code: Select all

#ifndef FRMOPTION_H
#define FRMOPTION_H

#ifndef WX_PRECOMP
	//(*HeadersPCH(frmOption)
	#include <wx/stattext.h>
	#include <wx/textctrl.h>
	#include <wx/panel.h>
	#include <wx/button.h>
	#include <wx/frame.h>
	//*)
#endif
//(*Headers(frmOption)
//*)

class frmOption: public wxFrame
{
	public:

		frmOption(wxWindow* parent,wxWindowID id=wxID_ANY);
		virtual ~frmOption();
//                void SetText(string Text)
//                {
//                        TextCtrl1->Text = Text;//what to write here!
//
//                }
//                string GetText()
//                {
//                        return TextCtrl1->text;//and what to write here!
//                }
		//(*Declarations(frmOption)
		wxStaticText* lbl;
		wxButton* Button1;
		wxPanel* Panel1;
		wxTextCtrl* TextCtrl1;
		wxTextCtrl tt;
		//*)

	protected:

		//(*Identifiers(frmOption)
		static const long ID_TEXTCTRL1;
		static const long ID_BUTTON1;
		static const long ID_STATICTEXT1;
		static const long ID_PANEL1;
		//*)

	private:

		//(*Handlers(frmOption)
		void OnButton1Click(wxCommandEvent& event);

		//*)
                wxTextCtrl TextCtrl;
		DECLARE_EVENT_TABLE()
};

#endif
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/

DavidHart
Site Admin
Site Admin
Posts: 3988
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart » Wed Dec 09, 2009 5:25 pm

Hi,
TextCtrl1.text = Text;//i dont know what to write here exactly
'TextCtrl1' is a class member pointer, so inside SetText() you can do:
TextCtrl1->ChangeValue( text );
(there are several other ways you could have done this too; did you look at the wxTextCtrl doc?).

That assumes that 'text' is a wxString, which is almost certainly should be. I suggest you only use std::string or C strings when communicating with the outside world.

Regards,

David

Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein » Wed Dec 09, 2009 6:46 pm

DavidHart wrote:Hi,
TextCtrl1.text = Text;//i dont know what to write here exactly
'TextCtrl1' is a class member pointer, so inside SetText() you can do:
TextCtrl1->ChangeValue( text );
(there are several other ways you could have done this too; did you look at the wxTextCtrl doc?).

That assumes that 'text' is a wxString, which is almost certainly should be. I suggest you only use std::string or C strings when communicating with the outside world.

Regards,

David
Thank You very much .
but why do we always use pointers to classes ? why dont we directly assign an object in wxwidgets?
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/

Debster
Knows some wx things
Knows some wx things
Posts: 32
Joined: Sat Aug 20, 2005 6:01 pm

Post by Debster » Wed Dec 09, 2009 8:10 pm

Hi,

Pointer have some advantages, in other languages you are using references. These are only some "special" pointers which can't be null. But sometimes a null pointer is very handy.

regards,
Debster

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Wed Dec 09, 2009 8:20 pm

Hi,
but why do we always use pointers to classes ? why dont we directly assign an object in wxwidgets?
In fact, it's rare to use a pointer to a class, not sure if I've ever tried that. The pointers are to objects.

The answer to your question lies with how an object is created. If it's on the heap:

Code: Select all

TextCtrl1 = new wxTextCtrl(...);
TextCtrl1->SetValue(wxT("I'm on the heap"));
Then you have a pointer to the object on the heap that last until you delete it or the program ends.

But if it's part of another object, or defined on the stack within a method, you can access the object directly.

Code: Select all

MyClass::MyMethod() {
    wxTextCtrl TextCtrl(...);
    TextCtrl.SetValue(wxT("I'm on the stack, I'm gone when this method finishes."));
...
}
Summary, if it's created using new, most likely you need to use "->" to reference the objects methods and variables.
You then to create objects on the heap because you don't usually know how many you need, or when you need them, or what ID you want them to have... etc. etc.

Hope that helps,

Jim


PS... Smoking isn't good for your lungs :wink:
OS: Vista SP1, wxWidgets 2.8.7.

Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein » Thu Dec 10, 2009 2:52 am

JimFairway wrote:Hi,
but why do we always use pointers to classes ? why dont we directly assign an object in wxwidgets?
In fact, it's rare to use a pointer to a class, not sure if I've ever tried that. The pointers are to objects.

The answer to your question lies with how an object is created. If it's on the heap:

Code: Select all

TextCtrl1 = new wxTextCtrl(...);
TextCtrl1->SetValue(wxT("I'm on the heap"));
Then you have a pointer to the object on the heap that last until you delete it or the program ends.

But if it's part of another object, or defined on the stack within a method, you can access the object directly.

Code: Select all

MyClass::MyMethod() {
    wxTextCtrl TextCtrl(...);
    TextCtrl.SetValue(wxT("I'm on the stack, I'm gone when this method finishes."));
...
}
Summary, if it's created using new, most likely you need to use "->" to reference the objects methods and variables.
You then to create objects on the heap because you don't usually know how many you need, or when you need them, or what ID you want them to have... etc. etc.

Hope that helps,

Jim


PS... Smoking isn't good for your lungs :wink:
Thank you very much.
now what if i want to send an object from of form to another .
in C# i would only do
and in our MainForm

Code: Select all

class MainForm :Form
{
     public MainForm()
     { 
         Initialize();
     }
     
     public string SetMainText
     {
           set{TextBox.Text = value;}
     }

     private void button1_Click(object sender, EventArgs e)
     {
        frmOption frm = new frmOption(this);
     }


}
//for example suppose we are in frmOption

Code: Select all

class FrmOption :Form
{
     MainForm mainForm;   
     FrmOption(MainForm frm)
     {
          mainForm = frm;
     }

     private void button2_Click(object sender, EventArgs e)
     {
        mainForm.SetMainText = "Hello";
     }
     
}   
how to do this in C++? i mean sending 'this' as a parameter! what is 'this' equivalent in C++?

//MainForm in C++

Code: Select all

class FormRelationFrame: public wxFrame
{
    public:

        FormRelationFrame(wxWindow* parent,wxWindowID id = -1);
        virtual ~FormRelationFrame();
        void SetMainText(wxString Text)
        {
                TextCtrl1->ChangeValue(Text);
        }
}
//frmMain.cpp

Code: Select all

void FormRelationFrame::OnButton1Click(wxCommandEvent& event)
{
       frmOption *frm  = new frmOption(this);//???is it right?

        frm->SetText(TextCtrl1->GetValue());
        frm->Show();
}

//frmOption.h in C++

Code: Select all

class frmOption: public wxFrame
{
	public:

		frmOption(wxWindow* parent,wxWindowID id=wxID_ANY);
		
//this is my constructor, i just tried to reference mainform object
                frmOption(wxWindow* parent,wxWindowID id=wxID_ANY,frmRelationMain *frmMain)
		{
		        MainForm =frmMain;
		}

		virtual ~frmOption();
} 


//and in frmOption.cpp

Code: Select all

void frmOption::OnButton1Click(wxCommandEvent& event)
{
        wxString string = _("string changed");
        MainForm.SetMainText(string); 
}  
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Thu Dec 10, 2009 8:02 am

Hi!
Hossein wrote:how to do this in C++? i mean sending 'this' as a parameter! what is 'this' equivalent in C++?
Well, to make things short: this is this :-)
I suppose in C# "this" might be a reference (I don't have any experience with C#), while in C++ it's a pointer as well.

You could modify your code a bit:

Code: Select all

class frmOption: public wxFrame
{ 
  frmRelationMain* MainForm;
  public:
    frmOption(frmRelationMain *frmMain,wxWindowID id=wxID_ANY)
    :wxFrame(frmMain,id)
    {
      MainForm = frmMain;
    } 
};
Now MainForm is a member variable of the type frmRelationMain* (pointer to frmRelationMain). Again, when using it, use "->" to access its methods. Due to inheritance you can pass frmMain in the ctor of wxFrame, as it is a wxWindow descendant as well.

May I point you to the wxWidgets tutorial in the top menu bar of this forum. IMHO it is a very complete first overview and a good starting point. For later you can find the wxWidget book on the wxWidgets website as a PDF (consider buying it though).
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein » Thu Dec 10, 2009 9:57 am

upCASE wrote:Hi!
Hossein wrote:how to do this in C++? i mean sending 'this' as a parameter! what is 'this' equivalent in C++?
Well, to make things short: this is this :-)
I suppose in C# "this" might be a reference (I don't have any experience with C#), while in C++ it's a pointer as well.

You could modify your code a bit:

Code: Select all

class frmOption: public wxFrame
{ 
  frmRelationMain* MainForm; 
  public:
    frmOption(frmRelationMain *frmMain,wxWindowID id=wxID_ANY)
    :wxFrame(frmMain,id)
    {
      MainForm = frmMain;
    } 
};
Now MainForm is a member variable of the type frmRelationMain* (pointer to frmRelationMain). Again, when using it, use "->" to access its methods. Due to inheritance you can pass frmMain in the ctor of wxFrame, as it is a wxWindow descendant as well.

May I point you to the wxWidgets tutorial in the top menu bar of this forum. IMHO it is a very complete first overview and a good starting point. For later you can find the wxWidget book on the wxWidgets website as a PDF (consider buying it though).
Thank You very much. i really appreciate your help .
i did what you told me but it seems im doing sth wrong! which i myself cant find it .
this is my frmOption.h !

Code: Select all

#ifndef FRMOPTION_H
#define FRMOPTION_H

#ifndef WX_PRECOMP
	//(*HeadersPCH(frmOption)
	#include <wx/stattext.h>
	#include <wx/textctrl.h>
	#include <wx/panel.h>
	#include <wx/button.h>
	#include <wx/frame.h>
	//*)
	#include "FormRelationMain.h"
#endif
//(*Headers(frmOption)
//*)

class frmOption: public wxFrame
{
        FormRelationFrame* MainForm;
	public:

		frmOption(wxWindow* parent,wxWindowID id=wxID_ANY);
		//secnd constructor
		frmOption(FormRelationFrame* frmMain, wxWindowID id=wxID_ANY):wxFrame(frmMain,id)
		{
		        MainForm =frmMain;
		}
		virtual ~frmOption();
                void SetText(wxString Text)
                {
                        TextCtrl1->ChangeValue(Text) ;

                }
                wxString GetText()
                {
                        return TextCtrl1->GetValue();
                }
		//(*Declarations(frmOption)
		wxStaticText* lbl;
		wxButton* Button1;
		wxPanel* Panel1;
		wxButton* Button2;
		wxTextCtrl* TextCtrl1;

		//*)

	protected:

		//(*Identifiers(frmOption)
		static const long ID_TEXTCTRL1;
		static const long ID_BUTTON1;
		static const long ID_STATICTEXT1;
		static const long ID_BUTTON2;
		static const long ID_PANEL1;

		//*)

	private:

		//(*Handlers(frmOption)
		void OnButton1Click(wxCommandEvent& event);
		void OnButton2Click(wxCommandEvent& event);
		//*)
                wxTextCtrl TextCtrl;
		DECLARE_EVENT_TABLE()
};

#endif
and it gives me :
F:\Coding Stuffs\Programming Stuff\Programming Center\C++\Sorce codes\WxWigets\FormRelation\frmOption.h|19|error: ISO C++ forbids declaration of `FormRelationFrame' with no type|
F:\Coding Stuffs\Programming Stuff\Programming Center\C++\Sorce codes\WxWigets\FormRelation\frmOption.h|19|error: expected `;' before '*' token|
F:\Coding Stuffs\Programming Stuff\Programming Center\C++\Sorce codes\WxWigets\FormRelation\frmOption.h|24|error: expected `)' before '*' token|
||=== Build finished: 3 errors, 0 warnings ===|
what am i doing wrong! ?
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Thu Dec 10, 2009 11:08 am

Hi

If I counted the line numbers correctly, it looks like 'FormRelationFrame' has not been declared prior to using it.
If you don't want to include the .h that defines it, you can add a single line to your code to tell the compiler what it is.

Change:

Code: Select all

//(*Headers(frmOption)
//*)

class frmOption: public wxFrame
{
        FormRelationFrame* MainForm;
        public:
...
to:

Code: Select all

//(*Headers(frmOption)
//*)
class FormRelationFrame;  // tells the compiler what it is, and you can declare things that are pointers to the class.

class frmOption: public wxFrame
{
        FormRelationFrame* MainForm;
        public:
...
Here's a link I found (google c sharp c++ differences) which gives the differences between C# and C++ that may help. I'm not familiar with C# either.
http://www.c-sharpcorner.com/UploadFile ... uages.aspx


Hope that helps,

Jim
OS: Vista SP1, wxWidgets 2.8.7.

Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein » Thu Dec 10, 2009 11:35 am

Thanks a million , its works like a charm .
and by the way that link of yours on C++ and C# syntax differences is just great .
:wink:
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/

TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV » Thu Dec 10, 2009 5:11 pm

Hossein wrote:but why do we always use pointers to classes ? why dont we directly assign an object in wxwidgets?
That's not specific to wxWidgets. It's more a C++ matter.

It seems you don't know that C# (like Java, amongst others) uses only references, which in fact is the smarter way to use... a pointer !
(nb: it's possible to use explicit pointers in C#, but i really can't see the purpose)

If in C# you can type "textBox.Text = smtg" that's just because C# provides properties, which is just a shortcut for using getters/setters.
The property "Text" of the object "textBox" is linked to the attribute "text" of this object.
(Fortunaltely, otherwise it would mean that C# allows encapsulation workaround! Awfull!!)

If you're trying to port some code/knowledge from C# to C++, just keep in mind this:
(C#) textBox.Text = smtg; --> (C++) textBox->SetText(smtg);
(C#) var = textBox.Text; --> (C++) var = textBox->GetText();

Don't want to be rude but it seems you're lacking some OOP basics. Please give a try to some books, your future C++/C#/Java/any_OOP_language developments will sure be greatly enhanced and simplified.

Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein » Fri Dec 11, 2009 3:35 am

TrV wrote:
Hossein wrote:but why do we always use pointers to classes ? why dont we directly assign an object in wxwidgets?
That's not specific to wxWidgets. It's more a C++ matter.

It seems you don't know that C# (like Java, amongst others) uses only references, which in fact is the smarter way to use... a pointer !
(nb: it's possible to use explicit pointers in C#, but i really can't see the purpose)

If in C# you can type "textBox.Text = smtg" that's just because C# provides properties, which is just a shortcut for using getters/setters.
The property "Text" of the object "textBox" is linked to the attribute "text" of this object.
(Fortunaltely, otherwise it would mean that C# allows encapsulation workaround! Awfull!!)

If you're trying to port some code/knowledge from C# to C++, just keep in mind this:
(C#) textBox.Text = smtg; --> (C++) textBox->SetText(smtg);
(C#) var = textBox.Text; --> (C++) var = textBox->GetText();

Don't want to be rude but it seems you're lacking some OOP basics. Please give a try to some books, your future C++/C#/Java/any_OOP_language developments will sure be greatly enhanced and simplified.
Thank you very much.
about OOP , yes i do . but i clearly understand set and get functions, and i know that c# in back stage is doing the same thing for its proprties like text.
you know i just kinda got confused , im not professional coder, so lately i was coding in c# and learned couple of OOP basics in C# which i didnt know when coding in c++.
anyways thanks alot for your help.
and by the way , i encountered a problem which i think is because of my lack of knowlegde about wxwidgets .
and this is
suppose i have a constructor like this

Code: Select all

frmOption(wxWindow* parent,wxWindowID id=wxID_ANY,FormRelationFrame* frmMain)
		{
		        MainForm =frmMain;
		}

now suppose i want to make an opbejct of frmOption in my main form, the last parameter would be this , but what about the first two ? i mean when making an object what should i send as parameter in ()?

Code: Select all

frmOption *frm = new frmOption( ?, ?,this); 
and also what does this mean ?

Code: Select all

frmOption *frm = new frmOption(0);
what is that 0? what happens if i make it 1?
and where can i find more information on these stuff ?
Thank you all in advance
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/

TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV » Fri Dec 11, 2009 10:00 am

Hossein wrote:suppose i have a constructor like this

Code: Select all

frmOption(wxWindow* parent,wxWindowID id=wxID_ANY,FormRelationFrame* frmMain)
		{
		        MainForm =frmMain;
		}

now suppose i want to make an opbejct of frmOption in my main form, the last parameter would be this , but what about the first two ? i mean when making an object what should i send as parameter in ()?

Code: Select all

frmOption *frm = new frmOption( ?, ?,this); 
You did write this constructor, not me! :)
I mean, if you don't know what are these 2 parameters related to, why using them??

In fact, this constructor looks like any other wxWidgets graphic object constructor:

Code: Select all

AnyWxWidgetsGraphicObject::AnyWxWidgetsGraphicObject(wxWindow* parent, int id, ...)
First parameter must not be NULL (except for the top window) and sets which is the parent of the object, generally the one which creates the graphic object. So this parameter is generaly set to "this".
Nb: It seems this parameter is now redundant with your 3td one!

Second parameter is the numeral identificator of the graphic object. It's used to handle events associated with the graphic object. If you don't need events, this parameter is set to "-1" (wxID_ANY is a macro for value "-1").

At last: you could safely write and use this constructor:

Code: Select all

frmOption(wxWindow* parent,wxWindowID id=wxID_ANY)
		{
		        MainForm =frmMain;
		}
and pass a FormRelationFrame object as the 1st parameter. I guess that the class FormRelationFrame is inherited from wxFrame, which is part of the wxWidgets classes hierarchy and which is inherited (not directly) from wxWindow class.
So where a wxWindow* object is wanted, you can safely use a FormRelationFrame* object (OOP once more ;)!)

Hossein wrote:and also what does this mean ?

Code: Select all

frmOption *frm = new frmOption(0);
what is that 0? what happens if i make it 1?
and where can i find more information on these stuff ?
You can find information in your code. I repeat: you did write it.
You cannot use this form of constructor (just one parameter) as the one you told us about has 3 parameters (and no default value for 3td one).
So, even if i can make some guess, i'll stay silent not to blur the whole thing.

Hossein
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Sep 21, 2008 7:23 am
Location: Somwhere nearby...
Contact:

Post by Hossein » Fri Dec 11, 2009 10:24 am

TrV wrote:
Hossein wrote:suppose i have a constructor like this

Code: Select all

frmOption(wxWindow* parent,wxWindowID id=wxID_ANY,FormRelationFrame* frmMain)
		{
		        MainForm =frmMain;
		}

now suppose i want to make an opbejct of frmOption in my main form, the last parameter would be this , but what about the first two ? i mean when making an object what should i send as parameter in ()?

Code: Select all

frmOption *frm = new frmOption( ?, ?,this); 
You did write this constructor, not me! :)
I mean, if you don't know what are these 2 parameters related to, why using them??

In fact, this constructor looks like any other wxWidgets graphic object constructor:

Code: Select all

AnyWxWidgetsGraphicObject::AnyWxWidgetsGraphicObject(wxWindow* parent, int id, ...)
First parameter must not be NULL (except for the top window) and sets which is the parent of the object, generally the one which creates the graphic object. So this parameter is generaly set to "this".
Nb: It seems this parameter is now redundant with your 3td one!

Second parameter is the numeral identificator of the graphic object. It's used to handle events associated with the graphic object. If you don't need events, this parameter is set to "-1" (wxID_ANY is a macro for value "-1").

At last: you could safely write and use this constructor:

Code: Select all

frmOption(wxWindow* parent,wxWindowID id=wxID_ANY)
		{
		        MainForm =frmMain;
		}
and pass a FormRelationFrame object as the 1st parameter. I guess that the class FormRelationFrame is inherited from wxFrame, which is part of the wxWidgets classes hierarchy and which is inherited (not directly) from wxWindow class.
So where a wxWindow* object is wanted, you can safely use a FormRelationFrame* object (OOP once more ;)!)

Hossein wrote:and also what does this mean ?

Code: Select all

frmOption *frm = new frmOption(0);
what is that 0? what happens if i make it 1?
and where can i find more information on these stuff ?
You can find information in your code. I repeat: you did write it.
You cannot use this form of constructor (just one parameter) as the one you told us about has 3 parameters (and no default value for 3td one).
So, even if i can make some guess, i'll stay silent not to blur the whole thing.
thank you very much .
let me tell you why i did use three parameters in my constructor .
before that let me tell you what i intended from writting such a thing .
all i wanted to was to send a text from my frmOption to my main form which here is FormRelationFram .
to achive this i needed to make an object of the main form ,
so i needed to send the FormRelationFram object by reference to frmOption and in frmOption access the properties of the mainform using that reference to main form.

i already said this in teh former posts in this topic and the form users kindly told me what to do .

and when i tried to make a constructor with only one parameter ( FormRelationFram* frm) i encountered a problem, then i tried add the needed parameter to the default constructor , thats why there are three parameters !
so to cut a long story short , did i do it the right way?
i mean is the procedure i took right?
where are my mistakes here ? ( in relating two forms? )
thank you in advance
Add-on Components (90)
Applications (183)
Development Tools (27)
Icons and Resources (1)
Sample Code and Project Templates (10)
Utilities (4)
wxWidgets (10)

http://www.wxcommunity.com/

TrV
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 630
Joined: Wed Jul 04, 2007 1:12 pm

Post by TrV » Fri Dec 11, 2009 11:59 am

Hossein wrote:[...]all i wanted to was to send a text from my frmOption to my main form which here is FormRelationFram .
to achive this i needed to make an object of the main form ,
so i needed to send the FormRelationFram object by reference to frmOption and in frmOption access the properties of the mainform using that reference to main form.

[...]

and when i tried to make a constructor with only one parameter ( FormRelationFram* frm) i encountered a problem,
What is the problem exactly?

For me 2 solutions:

- You don't need a specific method from FormRelationFrame class, and only need to access an inherited method from wxWindow:

Code: Select all

frmOption(wxWindow* parent,wxWindowID id=wxID_ANY) 
                { 
                        MainForm =frmMain; 
                }
- You need a specific method from FormRelationFrame class:

Code: Select all

frmOption(FormRelationFrame* parent,wxWindowID id=wxID_ANY) 
                { 
                        MainForm =frmMain; 
                }
If the 1st form leads to an issue, that's more a problem with code of frmOption class.

Previous post of JimFairway gives information about how to code that.

Post Reply