Solved

Public designers

Posted on 2000-02-22
7
170 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:mariab_
  • 4
  • 2
7 Comments
 
LVL 1

Author Comment

by:mariab_
ID: 2545508
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.
0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2545594
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.


0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2545602
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.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:mariab_
ID: 2545633
Adjusted points to 200
0
 
LVL 1

Author Comment

by:mariab_
ID: 2545634
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)
0
 
LVL 4

Accepted Solution

by:
wqw earned 200 total points
ID: 2545671
There is a way you can do this trough some kind of a form dispatcher object. This will not work for designers though.

You have a component dll with some forms which you want to instantiate in your standard exe late-bound. You get your name as string in the format of "component.formname". So, basicly you split sFormName to array, get the first part and concatenate ".CFormDispatcher", then CreateObject() with this progid. This diapater has a method GetForm(sFormName) for instance which accept second part of your "fully qualified form name":-). Here is the code for CFormDispatcher:

Function GetForm(sFormName) as Object
    Forms.Add sFormName
    Set GetForm = Forms(Forms.Count-1)
End Function

Unfortunately there is no Designers collection (btw, have you tried adding designer to Forms collection. It might work!)

HTH,

</wqw>
0
 
LVL 1

Author Comment

by:mariab_
ID: 2550065
Half solution - half of the points :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows 10 start screen issues 9 55
Excel - Save a copy of work book 13 89
Access 2013 combo box not working 3 51
Formula problem with Excel attachment 6 39
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question