Solved

Share classmodule between  2 projects

Posted on 2002-05-10
12
158 Views
Last Modified: 2010-05-02
Hi,

I have a projectgroup with Prj 1:(a dll and a class module). Prj 2: ocx there I like to have the same functionality as in the dll. This works fine if I copy the code in the class module  from Prj 1, into my control in the ocx project. But I should prefere to share the classmodule between the 2 projects.

So my Q is how to do this, so the public functions and sub's in the classmodule will be as methods in my ocx-controll, whithout pasting the code into the control?

Thanks :-)
0
Comment
Question by:Mr_Basic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 

Expert Comment

by:HeN_da_MaN
ID: 7000707
Compile the class as a .dll then make a reference to the dll in the two projects.

Hen
0
 

Author Comment

by:Mr_Basic
ID: 7000768
Hen, Thanks, but I like to have all in one file (dll or ocx) and the problem is still there...

To clearyfy, I know can write like this in the control:

Private MyCls As MyClass

Function MyMethods() As MyClass
    Set MyMethods = MyCls
End Function

But then in code the user have to write:

MyOcx.MyMethods.MyFunction

What I like is this

MyOcx.MyFunction

Same effect as when I paste the class code into the control.
0
 
LVL 3

Expert Comment

by:Gunsen
ID: 7000934
Simply add the class file (same as in prj1) into project2.  Sharing the same file, VB will detect this
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Mr_Basic
ID: 7000949
Gunsen, thanks I have done that, but as I explained:

Private MyCls As MyClass

Function MyMethods() As MyClass
   Set MyMethods = MyCls
End Function

But then in code the user have to write:

MyOcx.MyMethods.MyFunction

What I like is this

MyOcx.MyFunction

Same effect as when I paste the class code into the control.
0
 
LVL 3

Expert Comment

by:Gunsen
ID: 7000992
I do not see clear how MyOcx is instanciated ?
Why not only use:  MyCls.MyFunction ??

VB6 does not inherit class methods (vb-net does).
If i understand u right, u will have to wrap theese methods into your new class explicit.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 7001519
Do you mean setting the class' Instancing property to 6-GlobalMultiUse??
0
 

Author Comment

by:Mr_Basic
ID: 7001739
Gunsen ,

<Why not only use:  MyCls.MyFunction ??
Coz MyCls contains lots of functions, and it looks better and would be more simple to use with MyOcx.MyFunction1. Instead of calling them like: MyOcx.MyMethods.MyFunction1, MyOcx.MyMethods.MyFunction2...
One way to do it is to create simular functions in my ocx-control, who call the classmodule. But if I do changes in the classmodule I have to remember to do the same i the contoll. And that is what I like to avoid. Coz the classmodule is shared with other projects. But there maby is no way to do this in VB6, or??? Is that what you ment with "inherit class methods " ?

AzraSound, Thanks, but no...
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 7001785
You have a class with functions
You have an ocx with functions

You want the ocx to have the same functions as the class without actually referencing the class first (e.g., MyOCX.MyClass.ClassFunction)

This is not possible because the interface defintion of the OCX does not have the MyClass functions, so there is no way it could exude those functions.  COM works with interfaces, and if the interface defintion of one component says it does not have a function MyFunction, then no one can use that COM object and be expecting to be able to use the COM object by calling MyCOM.MyFunction.
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
ID: 7001787
Your only workaround may be to say:

Public Function MyFunction()
    Call MyClass.MyFunction
End Function
0
 

Author Comment

by:Mr_Basic
ID: 7002191
Thanks, in that case I could copy the code in the class into the control and delete the class instead.

I guess the "Implements" wouldn't help eider???
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 7002335
Implements allows you to define a common interface that other classes will share.  Classic example is the IAnimal interface, that maybe a Dog and Cat class may both implement.  I am not clear on what your actual design is here, but I dont know if an interface is really what you are after.  If you did create an interface defining your class functions and implemented it in your OCX, it really doesnt do you much good unless you tell your developers to create instances of the Interface class, not your OCX.

For example,

'IMyClass

Public Function MyClassFunction()
End Function


'MyOCX
Implements IMyClass

Private Function IMyClass_MyClassFunction()
End Function


Note that the implemented class' function is private.  To use it as if it were public, someone using your OCX would actually have to declare a variable of type IMyClass to call the MyClassFunction directly.

In the end, I dont think that even matters because an ocx doesnt work like an ActiveX DLL and classes do when it comes to an implemented interface.
0
 

Author Comment

by:Mr_Basic
ID: 7015992
AzraSound,

OK, thanks for your comment, I use the MyOcx.MyMethods.MyFunction now, I guess that it is the best way to keep the both projects (dll & ocx) simular.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 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