Solved

Share classmodule between  2 projects

Posted on 2002-05-10
12
154 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LINQ return type for nested group query 6 71
DO Loop not working 4 72
VB6 add a minute to the date time value 8 61
VBA color chart bars 12 78
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now