473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

classes and members

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
5 1206
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
2
by: Dave Veeneman | last post by:
Is is legal to declare abstract members in non-abstract classes? How about non-abstract members in abstract classes? I am writing a base class with three derived classes. The base class will...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
6
by: Peter Oliphant | last post by:
I just discovered that the ImageList class can't be inherited. Why? What could go wrong? I can invision a case where someone would like to add, say, an ID field to an ImageList, possible so that...
86
by: jopperdepopper | last post by:
Hi, finally giving php 5 a go, and going over the new approach to classes. Can someone clarify the public, private and protected to me? I quote the php manual: "The visibility of a property or...
16
by: chameleon | last post by:
I have 2 classes with exactly the same members (all static except dtor/ctor). Classes have different implementantion in only one static member function and first class has one more member...
3
by: Goyal | last post by:
I am trying to provide interface between C and C++ files. I am providing wrapper classes. Some classes contain protected members. Please suggest me how to use or ignore these protected members of...
17
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;"...
6
by: Miguel Guedes | last post by:
Hello, I recently read an interview with Bjarne Stroustrup in which he says that pure abstract classes should *not* contain any data. However, I have found that at times situations are when it...
5
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I am actually a VB.Net guy, but I have worked somewhat with C++ and C#. I just want to ask about the relationship between Abstract Classes and Interfaces. My first question is if...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.