CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2001
    Posts
    2

    VB Abstract Class

    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.


  2. #2
    Join Date
    Aug 2000
    Posts
    27

    Re: VB Abstract Class

    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.


  3. #3
    Join Date
    Sep 2001
    Posts
    2

    Re: VB Abstract Class

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured