Link to home
Start Free TrialLog in
Avatar of Mr_Basic
Mr_Basic

asked on

Share classmodule between 2 projects

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 :-)
Avatar of HeN_da_MaN
HeN_da_MaN

Compile the class as a .dll then make a reference to the dll in the two projects.

Hen
Avatar of Mr_Basic

ASKER

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.
Simply add the class file (same as in prj1) into project2.  Sharing the same file, VB will detect this
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.
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.
Do you mean setting the class' Instancing property to 6-GlobalMultiUse??
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...
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.
ASKER CERTIFIED SOLUTION
Avatar of AzraSound
AzraSound
Flag of United States of America image

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
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???
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.
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.