1. Bad Andy
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Rep Power

    BCB 6 global variables

    BCB has alot of event handlers when you get into bigger programs. There are many values which I need to use throughout all of them. I need to find out where you can globalize variables. In the header? You can declare them there but cannot set a value. Any help would be appreciated. Thanks
  2. #2
  3. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Fly-over country
    Rep Power
    Once solution using a header file was discussed a few days ago:
    How to re-assigned defined variables

    Another solution that can work in BCB is to use a DataModule. The original concept behind a data module was to put all of your connection controls, client datasets, etc. into a global class that could be accessed by all the forms. Since there is only one copy of this object created at program start, it can also be used to store global values. For example in my program under Project->Option->Forms, I Auto-Create my main MDI form and my DataModule. I store constants at the top of the .h file. I store global variables as public properties of the class. I also have some global functions which are methods of the class. Any initialization can be done in the DataModule constuctor. Then from my code I can call them like:

    UserName->Text = GlobalDM->UserName;

    Or I can have a central error logging routine I can call from any form:

    GlobalDM->ProcessError(ErrType, ErrNbr, ErrDescription, FormName, FormRoutine);

    I don't know if one method is better than the other. They have both worked for me.
    Last edited by dcaillouet; June 20th, 2003 at 01:56 PM.

IMN logo majestic logo threadwatch logo seochat tools logo