Re: Global objects

Tech-Archive recommends: Fix windows errors by optimizing your registry



"Alur" <Alur@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F18FDE9A-C98F-4BFC-A249-BDFA2EEEA8CF@xxxxxxxxxxxxxxxx
My VC++6 MFC exe project has many dialogs, menus .
It's necessary to have many global variables and objects.
For example, CRecordset objects(for different kind of server tables)
because it takes many time to load big tables
from a database for the each dialog box.
Could you tell me how and
where can I initialize them once in the app beginging and
use them many times from the different part of my application ?
Thanks in advance.

declare your globals as extern in your main header file (eg. extern int i;).
define them in you main cpp file (eg. int i;).
that way they are located in the main cpp file and available to all classes
that include your main h file.
the main h and cpp files generally have the same name as the project.

normally your main cpp file has an implementation of the InitInstance
method. in that method you can initialize all globals just before your main
window is shown. that way all classes that use your global can safely do so
once the main window is running.

--

Kind regards,
Bruno.
bruno_nos_pam_van_dooren@xxxxxxxxxxx
Remove only "_nos_pam"


.



Relevant Pages

  • Re: Problems with multiple CPP files in my project
    ... These globals are all wrong. ... // Window Globals ... Global declarations go in the phead.h file. ... extern int g_aWindowWidth; ...
    (comp.lang.cpp)
  • Re: window and the "good parts"?
    ... list of pre-defined globals that are included in the "assume a browser" ... The window is superfluous. ... | all global variables. ... It is error-prone to assume that a Window object is in the scope chain, ...
    (comp.lang.javascript)
  • Multiple instances of the same window
    ... Company window I list activities in a portal, ... For something trivial like this it doesn't much matter but for globals ... turning into a real problem. ... count to store globals eg. ...
    (comp.databases.filemaker)
  • window and the "good parts"?
    ... list of pre-defined globals that are included in the "assume a browser" ... The window is superfluous. ... | all global variables. ...
    (comp.lang.javascript)
  • Re: extern char and include practices
    ... If you have to use globals then the variable will be available to that file. ... A global variable in one file has scope throughout the whole ... What I do is use a "stdhdrs.h" which includes the common headers required ... > extern int lines;? ...
    (comp.lang.c)