Solved

Share classmodule between  2 projects

Posted on 2002-05-10
12
152 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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now