Properties as global variables 
Author Message
 Properties as global variables

Hi,

I made a simple interface with ATL for an application which used to be an
exe. I created one interface with some properties. Those properties are, for
an example, the database server name, the paths for some documents, etc.
Each property corresponds to a member variable of my interface class.

I need to use those data in many classes, and it's too complicated to create
member variables to hold them in each class. I didn't want to use global
variables, of course, so I thought it should be ok to create a single member
variable pointer to the interface class.

an example :

CMyProject (with IMyProject)
1 property MyProp <-> 1 member variable m_MyProp, public
1 method MyMethod (CClass1 c(this);)

CClass1
1 member variable (CMyProject* m_project;)
constructor which takes one CMyProject* parameter
1 method MyMethod2 (CClass2 c(m_project);)

CClass2
1 member variable (CMyProject* m_project;)
constructor which takes one CMyProject* parameter
1 method MyMethod3 (toto = m_project->m_MyProp;)

CClass1, CClass2 are not ATL classes, just generic classes.

Instead of doing this, would it be better to make the unique (I think it is
unique) CMyProject object accessible from all my other classes ? Do you have
another solution ?

Thanks for your help.

Fred



Fri, 29 Apr 2005 02:32:03 GMT  
 Properties as global variables
You say you are creating classes that need to access the property values of
your ATL class. If so, then these should be member classes. It's a lot
simpler than your design.


Fri, 29 Apr 2005 04:10:28 GMT  
 Properties as global variables
Sorry, but I don't understand your idea... Could you give me a small example
? Thanks
Quote:

> You say you are creating classes that need to access the property
> values of your ATL class. If so, then these should be member classes.
> It's a lot simpler than your design.



Fri, 29 Apr 2005 04:30:25 GMT  
 Properties as global variables
class ATL_NO_VTABLE CMyObject
{
    class MyPropertyList
    {
        XXX Property 1;
        YYY Property 2;
        etc.
     };

    MyPropertyList propertylist;

Quote:
}

If there are other classes that need to access all the properties, then you
can just pass the address of propertlist.

Is this what you are after?



Fri, 29 Apr 2005 05:32:03 GMT  
 Properties as global variables
Ok, I see. It's better (saffer) than my method, because it gives a more
restricted access to my ATL class, but I wouldn't say it is simpler. Instead
of passing a pointer to the ATL object, you pass a pointer to a member
variable of the ATL object.
Quote:

> class ATL_NO_VTABLE CMyObject
> {
>     class MyPropertyList
>     {
>         XXX Property 1;
>         YYY Property 2;
>         etc.
>      };

>     MyPropertyList propertylist;
> }

> If there are other classes that need to access all the properties,
> then you can just pass the address of propertlist.

> Is this what you are after?



Fri, 29 Apr 2005 06:28:21 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Is there a special property at global variable?

2. Global variable or not global variable

3. Uninitialized global data (was Re: Global variables)

4. Global Properties (i.e. application properties) in C#

5. static local variables vs global variables

6. Variables & Global Variables

7. global variables and external variables?

8. Why is not possible to assign a global variable to another global variable..?

9. Global properties set in Server accessible by Clients

10. Global variable

11. global variables

12. global variable

 

 
Powered by phpBB® Forum Software