Results 1 to 3 of 3

Thread: parent application to display an already instantiated control

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Location
    Los Angeles, CA
    Posts
    681

    Question parent application to display an already instantiated control

    Suppose you have created 2 users controls in the same activeX control project, 'Son' and 'Daughter'. An instance of Son is placed on a regular container - a form on a standard exe project. A method of Son is provided to create an instance of Daughter:

    Public Function MakeDaughter() As Daughter

    Dim d As Daughter
    Set d = CreateObject("Project1.Daughter")
    Set MakeDaughter = d

    End Function

    The idea is that I can call

    Dim daddysDaughter As Object
    '(because VB doesn't like a declaration as Daughter)
    Set daddysDaughter = Son1.MakeDaughter()

    from the parent application and daddy gets a nice reference to the daughter just created. So far so good, but... since my daughter is an ActiveX object, I need to display it somehow. My app requires Daughter to be displayed in a new window (read form), but as long as I know how to 'show' daughter, I can display it anywhere.

    Anyone any good idea? Thanks!

    Radu

  2. #2
    Fanatic Member BillBoeBaggins's Avatar
    Join Date
    Jan 2003
    Location
    in your database, dropping your tables.
    Posts
    628
    Maybe I am being too simple but what if on the form you are trying to 'Show' the instance of the 'Daughter' Control, you just specify its .Visible property to True? Daughter is a physical control and not just a Class right?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Location
    Los Angeles, CA
    Posts
    681
    right, but it actually doesnt help

    anyways, i kinda found a workaround. and this is: 'son' is not going to create an instance of 'daughter' right away. instead of doing that, 'son' would generate an event to its container form, asking it to dynamically create a 'daughter'. the container form would create that in the event handling routine with

    Dim DaughterCtl As VBControlExtender
    Set DaughterCtl = Controls.Add ("Project1.Daughter", "dauName")

    and will further manipulate that object with

    DaughterCtl.Object.someMethod
    DaughterCtl.Object.someProperty

    also, one of the event arguments would be a byref to the newly created object and would also be set inside the event handling procedure:

    Set retDaughter = Me.Controls.Items("dauName")

    returning the newly created object back to 'son' would give 'son' the possibility to work with the object just like it would have created it itself.

    kinda tricky, but it worked...

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