Page 1 of 1

whick radio box is checked?

Posted: Thu Oct 23, 2008 4:38 pm
by Mavverick
Hi!

I have a radiobox with 2 options: 1 robot or 2 robots.
and i need to open a certain frame if option 1 is checked and open a different frame if option 2 is checked.
so what do i have to use to get that?
like...

Code: Select all

void RobotsDlg::btnOKClick(wxCommandEvent& event)
{
	if (rdbNumRobots[1].checked == true)
	{
           JuntasFrm TempJuntasFrm(this);
           TempJuntasFrm.Show();
        }
}
obviously it's not working with that ".checked"... so what should i use instead?
thanks

Posted: Thu Oct 23, 2008 6:28 pm
by timg
If you are using a wxRadioBox, why would you not use GetSelection()?

Posted: Fri Oct 24, 2008 11:57 am
by Mavverick
yea.. i tried this:

Code: Select all

/*
 * btnOKClick
 */
void RobotsDlg::btnOKClick(wxCommandEvent& event)
{
      // insert your code here
      int GetSelection();
      if (rdbNumRobots->GetSelection() == 0)
      {
          JuntasFrm TempJuntasFrm(this);
          TempJuntasFrm.Show();
      }
)
and it's compiling.. but when i press the button OK, it's not opening my Juntas frame..
do u have any idea why? is it something wrong in my code?

Posted: Fri Oct 24, 2008 1:43 pm
by Mavverick
ah yea.. i think i can't use .Show with a Frame...
so do u know how could i do to open a frame with a button click?

Posted: Fri Oct 24, 2008 6:13 pm
by timg
Mavverick wrote:yea.. i tried this:

Code: Select all

/*
 * btnOKClick
 */
void RobotsDlg::btnOKClick(wxCommandEvent& event)
{
      // insert your code here
      int GetSelection();
      if (rdbNumRobots->GetSelection() == 0)
      {
          JuntasFrm TempJuntasFrm(this);
          TempJuntasFrm.Show();
      }
)
and it's compiling.. but when i press the button OK, it's not opening my Juntas frame..
do u have any idea why? is it something wrong in my code?
Is the frame supposed to be Modal? Otherwise, I think your form object will quickly drop out of scope and be deleted.

Posted: Fri Oct 24, 2008 7:27 pm
by Mavverick
ah yea.. that is what happens i think!!

like.. when the program starts, a dialog opens.. so there u have 2 options, u are gonna choose one e click OK..
now that dialog closes (i forgot about that.. i didnt make it to close yet) and it opens the frame!
does it have to be modal?? if yes, how can i do that? or if i want to be modal, i have to use a wxdialog?

Posted: Fri Oct 24, 2008 8:42 pm
by timg
No, it doesn't have to be Modal. If you want to do what you describe, maybe you should have a member variable in your
application and create the frame using new in your dialog.

Something like this:

Code: Select all

//declared in myApp?
JuntasFrm*   myJuntasFrm;

void RobotsDlg::btnOKClick(wxCommandEvent& event)
{
      // insert your code here
      int GetSelection();
      if (rdbNumRobots->GetSelection() == 0)
      {
          myJuntasFrm = new JuntasFrm(this);
          myJuntasFrm->Show();
      }
)

Posted: Fri Oct 24, 2008 10:16 pm
by Mavverick
Oh man.. almost there!
i wrote this:

Code: Select all

void RobotsDlg::btnOKClick(wxCommandEvent& event)
{
    // insert your code here
    JuntasFrm*   myJuntasFrm;
    JuntasUmFrm*   myJuntasUmFrm;
    int GetSelection();
    if (rdbNumRobots->GetSelection() == 1)
    {
        myJuntasFrm = new JuntasFrm(this);
        myJuntasFrm->Show();
    }
    else
    {
        myJuntasUmFrm = new JuntasUmFrm(this);
        myJuntasUmFrm->Show();
    }
    Destroy();
}
And that thing still happens: the frames show up, but disappear in a fraction of seconds =(
Do u know what is still wrong?
Thanks for the help until now!

Posted: Fri Oct 24, 2008 10:30 pm
by timg
It's probably deleting your pointers when the Dialog is detroyed and deleting whatever it is that they are pointing to.

Try putting the pointer variables into whatever it is that creates the Dialog.

Posted: Tue Oct 28, 2008 11:31 am
by Mavverick
I solved it by not using Destroy() anymore..
Thank you very much for the help!