PDA

Click to See Complete Forum and Search --> : Class inside a class


abdul
Jun 9th, 2002, 02:05 PM
I am basically trying to create a class that "has another class' functions, variables" in it. For example in some activex controls, it's like

MyControl.Show
MyControl.DoSomething
MyControl.Extra.DoOtherStuff

How would you implement last technique? It you have a structure in the class, it would be same as last one but then it would only support variables (no functions). Is it like the main (MyControl) is a derieved class and Extra is the base class?

CornedBee
Jun 9th, 2002, 02:30 PM
You're confusing two things. In particular, Automation and C++ classes. Those two have nothing in common.

For C++ classes, it is easy:

class A {
public:
int i;
};
class B {
public:
A a;
};

B b;
b.a.i = 5;

abdul
Jun 9th, 2002, 02:36 PM
I've heard of Automation but I'm not familiar with its concepts. For the example that you just presented, I think it's impossible for class a to access some of the data in class b, right?
I actually have a "Button" class as class b and a "Font" class as class a which is responsible for setting different charactertics of the font OF THE BUTTON (class b). I don't see anyway to, let's us, make class a access a varible (hWnd) of class b, so should I just stick with putting all the functions in class b?

CornedBee
Jun 9th, 2002, 02:46 PM
Automation is far more complicated. Basically, if you access a property that is an object (like controls on a VB form), the interpreter will translate this line:
Form1.Button1.Caption = "Hello"
to the following automation calls:
Form1 is an IDispatch interface, do the property get calls for "Button1" on it. Return value is another IDispatch interface. Do the property set calls for "Caption" on this interface, passing the string "Hello".

That is a total of 4 function calls btw, not including preparation of the argument arrays, extraction of return values and possible internal function calls.

CornedBee
Jun 10th, 2002, 02:31 PM
You can give the font a reference of some kind to the button. But why does the font need to set characteristics of the button? Sounds strange to me.

abdul
Jun 10th, 2002, 02:36 PM
I just wanted to create a button or label or whatever control similar to the one found in VB (.NET especially). In that button, you can set the "Caption" of of that button by saying

Button.Caption =

But it has divided different type of properties into different categories. So to set the font to bold, you can call

Button.Font.Bold = True

So it just kind of organizes different properties of the button.

CornedBee
Jun 10th, 2002, 02:51 PM
But bold is a property of the font, not of the button. The font itself is a property of the button, so changes to the font will reflect in the appearance of the button. Since the font is selected into the device context at drawing time, you only need to invalidate the button after you set a property. The VB framework does that automatically for you.

abdul
Jun 10th, 2002, 03:09 PM
True, but I guess I'll just stick with declaring all the functions in the "Button" class because with multiple objects, it becomes kind of messy.