Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Share classmodule between  2 projects

Posted on 2002-05-10
12
Medium Priority
?
163 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
  • 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
Independent Software Vendors: 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 400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…
Suggested Courses

916 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