doublemax wrote:quite obvious, the global variable "mainframe" is not initalized at that point in time.
Well, You are correct, I did not initialize mainframe. I did not do this because I thought that the very first thing that happened when executing my applications code was to assign the mainframe variable (see the indicated statement)
Code: Select all
//This is the main application file. It gets run as the very first thing
//Create some GLOBAL variables which are event sources:
Analyzer *mainframe;
IMPLEMENT_APP(AnalyzerApp)
bool AnalyzerApp::OnInit()
{
mainframe = new Analyzer(NULL); //<-THIS IS THE ASSIGNNEMT, AND IT SEEMS TO BE DONE
// //BEFORE ANYTHING ELSE IN THE APPLICATION CODE
{....}
}
doublemax wrote:Global variables are usually bad and in this particular case certainly not necessary.
I agree, They are distasteful and no end of trouble. But Even more distasteful is having to pass the mainframe pointer when creating a child of a child of a child....
Is there another way to determine the mainframe pointer other than using a global or explicitly passing it to children?
doublemax wrote:If you don't want to change anything now, put a "mainframe=this;" at the first line into your Analyzer ctor.
I will try it. But I thought that mainframe would have been assigned that value by then
doublemax wrote:Any you really should learn how to use a debugger, errors like this are easily detected in a debugger while looking at the code you can spend hours without seeing the mistake.
You mean the the backtrace? Yes, it seems quite cryptic. I have looked at the backtrace, but I can not tell where it is trying to say that the crash occurred.
-Tony
EDIT:
P.S. I made the change you suggested to initialize mainframe to "this" in the Analyzer class in AnalyzerMain.coo. I then changed the variable name when instantiating the class in Anallyzer.App.cpp.
AND IT WORKED! All of it! Even the ability to catch the event even when it is posted to some other class. And ALL the instances of the GraphicsWindow class see the event. This achieves my goal! THANK YOU.
I still don't know why the statement
"mainframe = new Analyzer(...);"
is not equivalent to the statement
"mainframe = this;" when written inside the Analyzer class. I thought that the two pointers were equivalent.
-T