classes and members

R

rory

Hi everyone. I am developing a program using wxWidgets, but my problems
are more to do with general C++ practices so I've decided to ask here
rather than on the wxWidgets list. I have a main class, my frame class,
which contains lots of GUI controls I need in my application. I've also
derived a new class, wxLoopStation, from the MDIChildFrame base class.
I create an objects of this class in one of my main frame class member
functions and it all goes fine. The problem is when I try to access a
member variable of wxLoopStation I keep getting a crash, the program
simply hangs there? Any ideas? Here is some pseudo code from my app:

//wxLooperFrame is my main class....
void wxLooperFrame::CreateChildFrame()
{
//create a new child frame...
loopStation=new wxLoopStation((wxMDIParentFrame*)this, -1, "Loop1",
wxPoint(20, 20), wxSize(215, 255));
//create a text box in new child frame
loopStation->freqText = new wxTextCtrl(panel, -1, "1",wxPoint(140,
24), wxSize(40, 20), wxTE_READONLY);
}

void wxLooperFrame::ButtonClick()
{
//read text from loopStation's text control
wxMessageBox(loopStation->freqText->GetLabel());
}

So whenever ButtonClick() is called I get a crash. Any ideas? I hope
it's something simple!

Rory.
 
S

Stuart Redmann

rory said:
void wxLooperFrame::ButtonClick()
{
//read text from loopStation's text control
wxMessageBox(loopStation->freqText->GetLabel());
}

So whenever ButtonClick() is called I get a crash. Any ideas? I hope
it's something simple!

When using pointers, you should always make sure that the pointers
actually point somewhere. Easiest thing for your code would be to set a
breakpoint at ButtonClick and examine the pointers. In general it would
be a good practise to use some kind of ASSERT meachnism, like Visual C
provides:

void wxLooperFrame::ButtonClick()
{
//read text from loopStation's text control
ASSERT (loopStation);
ASSERT (loopStation->freqText);
wxMessageBox(loopStation->freqText->GetLabel());
}

When not avaluating to true, the assert will pop up a little debug
window at run-time, so that you can trace into your code conveniently.

Regards,
Stuart
 
R

rory

Thanks Stuart, unfortunately I am using mingw and don't have it st up
for debugging, nor would I know how to use that debugger even if I did
have it set up. From looking at the code can you see any obvious
reasons why I can't call the GetValue() method? Given that loopStation
is a member variable of wxLooperFrame I should be able to call all its
public methods from any of wxLooperFrames member functions, right?
Thanks for the help.

Rory.
 
V

VJ

rory said:
Thanks Stuart, unfortunately I am using mingw and don't have it st up
for debugging, nor would I know how to use that debugger even if I did
have it set up. From looking at the code can you see any obvious
reasons why I can't call the GetValue() method? Given that loopStation
is a member variable of wxLooperFrame I should be able to call all its
public methods from any of wxLooperFrames member functions, right?
Thanks for the help.

Rory.

Might be a stupid question, but: are you sure CreateChildFrame() is called?

You might want to initialize loopStation to NULL in the constructor, and
check if it is still NULL in ButtonClick() to make sure
 
S

Stuart Redmann

rory said:
> Thanks Stuart, unfortunately I am using mingw and don't have it st up
> for debugging, nor would I know how to use that debugger even if I did
> have it set up. From looking at the code can you see any obvious
> reasons why I can't call the GetValue() method? Given that loopStation
> is a member variable of wxLooperFrame I should be able to call all its
> public methods from any of wxLooperFrames member functions, right?

If you tried to access a member variable or a member function that is
not public, the compiler would have complained.

Stuart
 
R

rory

Might be a stupid question, but: are you sure CreateChildFrame() is called?
You might want to initialize loopStation to NULL in the constructor, and
check if it is still NULL in ButtonClick() to make sure

I'm sure it's been called, if it wasn't I wouldn't be seeing the
MDIChildFrame appear on screen as that is the only place I call the
constructor for the loopStation class. I might try the wxWidgets list
and see what they think. Thanks for all te help

Rory.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top