Results 1 to 8 of 8

Thread: Class inside a class

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Class inside a class

    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?
    Baaaaaaaaah

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You're confusing two things. In particular, Automation and C++ classes. Those two have nothing in common.

    For C++ classes, it is easy:
    Code:
    class A {
    public:
    int i;
    };
    class B {
    public:
    A a;
    };
    
    B b;
    b.a.i = 5;
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    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?
    Last edited by abdul; Jun 9th, 2002 at 02:40 PM.
    Baaaaaaaaah

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    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.
    Baaaaaaaaah

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    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.
    Baaaaaaaaah

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width