Elemental problem with scope Topic is solved

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
pottsmgg
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Aug 19, 2010 2:32 pm

Elemental problem with scope

Post by pottsmgg »

As you can see. I am new to Ubuntu and wx widgets.
My time with C++ is limited to MS Visual C# and C++.
I am told it is not possible to change a Buttons color from green to red using a datetime ticks. The answer is to draw your own.
I am trying the project with widgets. I have a problem with te following code. It seems elementry but I cant solve it.

Code: Select all

void toggle_2Frame::OnButton1Click(wxCommandEvent& event)
{

***************************************************
OK
    this->Panel2->Show();
***************************************************
    /* wxMessageBox( _("This is a wxWidgets Hello world sample"),
                  _("About Hello World"),
                  wxOK | wxICON_INFORMATION, this);  */
     wxMessageBox( _("Click Again"));
***************************************************
OK
      this->Panel2->Hide(); 
***************************************************

}

void togglepanel2(void)
{
    if(panel_status == true)
    {
    panel_status = false;
**********************************************
    this->Panel2->Hide(); 
  
/toggle_2Main.cpp|132|error: invalid use of 'this' in non-member function

***********************************************
    else
    {
    this->Panel2->Show();
    panel_status = true;
    }
}
EDIT by Auria : please use code tags
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

First, please use code tags when posting code.
Second, I don't really understand the code you posted.

The part where it says "error: invalid use of 'this' in non-member function" is a very clear error message, you cannot use "this" outside of classes; are you familiar with object-oriented programming?
"Keyboard not detected. Press F1 to continue"
-- Windows
pottsmgg
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Aug 19, 2010 2:32 pm

Post by pottsmgg »

Sorry I don't know what code tags are.

This compiled OK

***************************************************
OK
this->Panel2->Hide();
***************************************************

This is line 132 did not compile.

**********************************************
this->Panel2->Hide();

/toggle_2Main.cpp|132|error: invalid use of 'this' in non-member function

***********************************************

The question is Why.

Martin
jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche »

Because you invoke this outside the class. You created a function instead of a class method.

You used

Code: Select all

void togglepanel2(void)
instead of

Code: Select all

void toggle_2Frame::togglepanel2(void)
.
Jérémie
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

"Keyboard not detected. Press F1 to continue"
-- Windows
pottsmgg
In need of some credit
In need of some credit
Posts: 5
Joined: Thu Aug 19, 2010 2:32 pm

Post by pottsmgg »

Thanks for your patience.
I was able to blink the panel with the timer, something I could not do with MS Visual Basic, C# , C++.
This was my first experience with Linex>
Thanks Martin
Post Reply