Posted by Remmie on 2001-01-12
Subject: Global headers and Global Variaboles. C++ builder goes a bit far in encouraging proper OOP techniques, your APP is a class, your forms are classes etc etc.. For a form to have access to another form you must include the target forms header into the accessing forms unit file. You would think all forms in your app could access all forms but this is not the case, to do this you would have to add every forms header to every forms unit file, as far as i know this is how Inprise intend (see the Include header option in file menu). Global variables are discouraged in OOP, one way around this is add a variable to your main form header file as part of its class, add the main forms header to each form unit file, and access it from the main form class, eg Form1->MyVar - works for me :) (You can also simply make it global in a header file and include that in all units, i do this with global consts) Hope this helps! Remmie -----Original Message----- >> >Date: Fri, 12 Jan 2001 13:50:45 -0000 >From: "christopher.lambell" <christopher.lambell@xxx.xx.xx> >Subject: Global headers and Global Variaboles. > >After using DOS based C++ for years, I decided to purchase Borland C++ >builder 4 and give windows programing a crack. The only difficulty I seem to >have is that I cant declare headers globally so that all forms can access >them, in DOS based based programing I would declare the standard headers, >then my headers obviously outside function main. I normally start by >declsaring a header file containg my classes and member functions, and then >go on to declare my header files which contain functions called by main >which use the already defined objects. > >Using C++ builder I have to declare the header containing my classes and >member functions at the start of each form. > >I also can't find a way of declaring a global variable that can be seen by >all forms without redeclaring it and using the 'extern' key word in every >form. > >Any experienced or semi experienced Borland programmers have any >suggestions? > >Cheers > >Chris >
Previous post | Next post | Timeline | Home