Click to See Complete Forum and Search --> : VB Abstract Class


Duuude
September 27th, 2001, 10:23 AM
Heya, I'm trying to figure out how to implement an abstract class in VB6. Sounds simple enough, right ? Well wrong, cause I'm having lots of troubles. Any help would be greatly appreciated.

Here's what I have :

'-------------------------------------------
(Project1 : class "Interface") <-- This is an ActiveX DLL project

Public Function Load()
End Function
'-------------------------------------------
(Project 2 : class "Implementation1") <-- this is also an ActiveX DLL Project. "Implementation1" has a reference to Project1

Implements AbstractClass.Interface

Private Function Interface_Load()
Interface_Load = "Hello World"
End Function


Now I create a form with a button and a textbox. When I click the button, I want the results from my Load method to be displayed in the textbox. Here's the code for (Project3 : Form1 ) where Form1 has a reference to Project1.

Private Sub Command1_Click()

Dim objX As Project1.Interface
Set objX = CreateObject("Implementation1")

Text1.Text = objX.Load()
End Sub


===============================
Now my problem is that when I run this program, I get the error message "ActiveX component can't create Object" and the error occurs on the 'Set objX = CreateObject(Implementation1)' line of my Form procedure.

What am I doing wrong ? Thanks for your help in advance.

Strat
September 27th, 2001, 02:33 PM
1) In project 3, you need to reference the 2nd project, not the project 1 interface. Try using:

Dim objX As Implementation1
Set objX = new Implementation1

2) The Interface_Load function needs to be Public to expose it to project 3.

3) Set Text1.Text = objX.Interface_Load()

I believe that should do it.

Duuude
October 1st, 2001, 10:35 AM
okay, that solves the error, but it's no longer an abstract class ( which is my main purpose ).

I want to be able to reference any implementation of the methods in Project1 from an outside source, and your solution does not make any reference to Project1.

The idea is that my department defines the structure of the abstract class in Project1 and another department(s) define their own implementaion ( i.e. the "guts" ) or this class somewhere else.

And then, then end product selects different implementations of the class, dependant on which department we are dealing with. So I will eventually want to make reference to my Load member like this : Project1.Interface("Implementation1").Load() instead of Implementation1_Load()

But thanks anyway for your help :)