Results 1 to 8 of 8

Thread: Loading OCX Runtime

  1. #1

    Thread Starter
    Fanatic Member petrus's Avatar
    Join Date
    May 2002
    Location
    pBytes[sizeof(pBytes)/2]
    Posts
    553

    Loading OCX Runtime

    Hello,
    I want to load an OCX into my app at runtime, the OCX should be placed in the app's dir.
    The app shouldn't know anything about the OCX at design time.
    ICQ: 128716725

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Can you make yourself clear? You want to use an OCX which isn't par of your program?
    Roy

  3. #3

    Thread Starter
    Fanatic Member petrus's Avatar
    Join Date
    May 2002
    Location
    pBytes[sizeof(pBytes)/2]
    Posts
    553
    First, thankyou for answering fast.
    The OCX isn't a part of the App, it's just a OCX in the app's directory.
    I want to do something like this:

    VB Code:
    1. dim MyOCX
    2.  
    3. set MyOCX = CreateObject("MyApp.MyOcx")

    This will result in an ActiveX Can't Create Object error.
    ICQ: 128716725

  4. #4
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    As far as I can understand you want to create an instance of some OCX directly on your form? Is that right? If yes then you have an issue: first it's not a CreatObject function but instead an Add method of Controls collection. Second, it must be registered and licensed in order to activate it at run time.
    Roy

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by IROY55
    As far as I can understand you want to create an instance of some OCX directly on your form? Is that right? If yes then you have an issue: first it's not a CreatObject function but instead an Add method of Controls collection. Second, it must be registered and licensed in order to activate it at run time.
    Yeah, what he said.... in addition, some third party controls resist being added at run time....It's how they ensure they are being used legitly.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Member
    Join Date
    Dec 2000
    Location
    UK
    Posts
    39
    IROY is correct about the Registering. If everything is registered Ok then the easiest way I have found is to use the VBControlExtender (assuming you want to recieve events from the Control you have added).

  7. #7

    Thread Starter
    Fanatic Member petrus's Avatar
    Join Date
    May 2002
    Location
    pBytes[sizeof(pBytes)/2]
    Posts
    553
    VBControlExtender? What's that?
    ICQ: 128716725

  8. #8
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    From MSDN:
    Represents the Visual Basic VBControlExtender properties.

    Syntax

    VBControlExtender

    Remarks

    The VBControlExtender object is primarily used when dynamically adding a control to the Controls collection using the Add method. The VBControlExtender object is particularly useful for this purpose because it provides a generic set of properties, events, and methods to the developer. Another feature of the object is the ObjectEvent event which is designed to parse any event raised by a dynamically added control. The example below declares an object variable as VBControlExtender, and sets the variable when adding a control. The example also shows how you can program the ObjectEvent event.

    VB Code:
    1. Option Explicit
    2. Dim WithEvents objExt As VBControlExtender ' Declare VBControlExtender variable WithEvents
    3.  
    4. Private Sub LoadControl()
    5.    Licenses.Add "Project1.Control1", "ewrinvcmcoe"
    6.    Set objExt = Controls.Add("Project1.Control1", "myCtl")
    7.    objExt.Visible = True ' The control is invisible by default.
    8. End Sub
    9.  
    10. Private Sub extObj_ObjectEvent(Info As EventInfo)
    11.    ' Program the events of the control using Select Case.
    12.    Select Case Info.Name
    13.    Case "Click"
    14.       ' Handle Click event here.
    15.    ' Other cases now shown
    16.    Case Else ' Unknown Event
    17.       ' Handle unknown events here.
    18.    End Select
    19. End Sub
    Restrictions on Setting the References to the Variable
    There is one caveat to be aware of when setting the VBControlExtender object to a dynamically added control: intrinsic controls cannot be set to the variable

    End of MSDN quote
    Roy

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