How to setup Application wide variables

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
agam3
In need of some credit
In need of some credit
Posts: 2
Joined: Mon Dec 20, 2004 7:14 pm

How to setup Application wide variables

Post by agam3 » Tue Apr 26, 2005 4:30 pm

I'm new at windows programming and a little rusty with my C++ skills.

I need to setup some global variables that are accessible everywhere in the application.

I have the typical classes such as the "Application" class which "contains" the Frame class which gets instantiated inside the OnInit method of the Application class.

I created private variables in the Application class then I defined public get and set methods also in the application class. I will call these "get/set" methods from inside an event handler which is obviously part of the Frame class.

My two main issues are:

First issue is that I dont know the name of the object that the IMPLEMENT_APP macro creates, therefore I dont know the object name to use to invoke the get method of the Application class.

Second issue: Is my approach correct or is there a another cleaner more standard way to accomplish this?

Thanks
AL

cg
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 201
Joined: Sun Aug 29, 2004 12:33 am
Location: Canada
Contact:

Post by cg » Tue Apr 26, 2005 4:33 pm

You can add them to your application class. Then in a form or class where you need access just add:

Code: Select all

#include "app.h"
and you can use

Code: Select all

wxGetApp().myvar
to access it.

HTH

Chris

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Tue Apr 26, 2005 5:56 pm

cg wrote:You can add them to your application class. Then in a form or class where you need access just add:

Code: Select all

#include "app.h"
and you can use

Code: Select all

wxGetApp().myvar
to access it.

HTH

Chris
If you're using it in another file besides your main implementation file you may need to do something like ((MyApp*)wxTheApp)->myvar
[Mostly retired moderator, still check in to clean up some stuff]

Post Reply