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.
Printable View
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.
Can you make yourself clear? You want to use an OCX which isn't par of your program?
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:
dim MyOCX set MyOCX = CreateObject("MyApp.MyOcx")
This will result in an ActiveX Can't Create Object error.
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.Quote:
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.
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).
VBControlExtender? What's that?
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.
Restrictions on Setting the References to the VariableVB Code:
Option Explicit Dim WithEvents objExt As VBControlExtender ' Declare VBControlExtender variable WithEvents Private Sub LoadControl() Licenses.Add "Project1.Control1", "ewrinvcmcoe" Set objExt = Controls.Add("Project1.Control1", "myCtl") objExt.Visible = True ' The control is invisible by default. End Sub Private Sub extObj_ObjectEvent(Info As EventInfo) ' Program the events of the control using Select Case. Select Case Info.Name Case "Click" ' Handle Click event here. ' Other cases now shown Case Else ' Unknown Event ' Handle unknown events here. End Select End Sub
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