Link to home
Start Free TrialLog in
Avatar of mariab_
mariab_

asked on

Public designers

How can I expose a designer or a form whitin a component to be public from outside?

The aim is to create an instance of it using CreateObject
Avatar of mariab_
mariab_

ASKER

I dont want to create a class in this component with public function and pass the name of the designer or a form as a parameter to it.
I'm not sure whether this is what you want to achieve, but you could try something like this:

Create a new project (ActiveX.dll) and name it test

Insert a form (frmTest), with all the code and controls you want.

Copy-paste this code into your class module (Class1):

Option Explicit

Public MyForm As Object

Private Sub Class_Initialize()
    Set MyForm = New frmTest
End Sub

Private Sub Class_Terminate()
Set MyForm = Nothing
End Sub

You can now add a new project (standard .exe), add a reference to project 'test' and insert this code in the form module:

Private Sub Form_Load()
Dim xx As Test.Class1
Set xx = New Test.Class1

    xx.MyForm.Show
End Sub

It does what I think you want, though there is one little catch for the developer:

Since you use late binding, at design time you want get the intelli-sense functionality you're grown used to (i.e. when you type xx. you'd expect a pop-up showing you 'MyForm' etc...)

You can 'trick' VB into doing that when you change the declaration part in the class module:
Public MyForm As new frmTest

Though this line would give you a compile error, at least at designtime, you'll get the nice pop-ups.


It is not possible to create an instance of it directly (forms etc. are considered to be private to a component or dll) though in this way you can create a class that does nothing but to create the form (or designer) and pass the object to the caller. Of course if you prefer CreateObject over Dim x as new y, or Dim x as y -> Set x=new y, you're welcome to do it that way.
Avatar of mariab_

ASKER

Adjusted points to 200
Avatar of mariab_

ASKER

I have to clear this out!

Imagine that the name of the form or the designer or the activex control is stored in a database field and the only way to create an instance of it is to use LATE BINDING.

In case of activex control everithing is OK because there are public property which you can set to true.

But in case of Form or Designer (such as Data Report or any) there are no property to set.

Is there any way to do this:

Dim sFormName as String
Dim oFrm as Object
Set oFrm = _
CreateObject("prjFormStorage." & _ sFormName)
ASKER CERTIFIED SOLUTION
Avatar of wqw
wqw

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mariab_

ASKER

Half solution - half of the points :)