By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

classes and members

P: n/a
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.

Nov 3 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
rory wrote:
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
Nov 3 '06 #2

P: n/a
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.
Stuart Redmann wrote:
rory wrote:
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
Nov 3 '06 #3

P: n/a
VJ
rory wrote:
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.
Stuart Redmann wrote:
>>rory wrote:
>>>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

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
Nov 3 '06 #4

P: n/a
rory wrote:
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
Nov 3 '06 #5

P: n/a
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.

Nov 3 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.