?
Solved

Compile error with Implements..

Posted on 2003-03-15
11
Medium Priority
?
1,690 Views
Last Modified: 2009-07-29
HI -

Visual Basic 6.
Project type is an ActiveX DLL

I have a class: IOutput_Script_Factory which is intended as an abstract interface. It defines one method:

Public Function CREATE_INSTANCE(ByVal sType As String) As IOutput_script
End Function

Its Instancing type is set at PublicNOtCreatable

I then have a concrete implementation class: Output_Script_Factory:

Implements IOutput_Script_Factory

Private Function IOutput_Script_Factory_CREATE_INSTANCE(ByVal sType As String) As Ioutput_script
    ' code
End Function

iT too is PublicNotCreatable

The problem is, the DLL won't compile. I get a VB Error:

Compile Error:
Object module needs to implement 'CREATE_INSTANCE' for interface 'IOutput_Script_Factory'


What's going on here?  my object module does implement the expected interface.. granted, there's no code in there just yet, as I'm just putting the skeletons together.. but even if i put something in there I get the same error. I must be missing something obvious but I can't figure out what.


thanks
-Paul

0
Comment
Question by:PMH4514
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 11

Expert Comment

by:rdrunner
ID: 8142434
When you choose to use IMPLEMENTS in VB you have to make sure that your "new" class supports THE COMPLETE INTERFACE of the class it implements.

So if the class IOutput_Script_Factory has a property "scripttext" then the above example wont compile...

VB does not really support inheretance... You have to implement every property in the new class by hand..

Hope this helps
0
 

Author Comment

by:PMH4514
ID: 8142481
Yes I know. I've posted the complete code body for both classes. the factory class (Output_Script_Factory) I've defined an interface for a single method - CREATE_INSTANCE.. and then I attempt to implement that interface in the Output_Script_Factory class.  there are no other method signatures or properties defined.. hmmm..
0
 
LVL 11

Expert Comment

by:rdrunner
ID: 8142514
How about Private vs Public ? ;)

the 2nd class has only a private function ...
0
Industry Leaders: 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:PMH4514
ID: 8142553
HMM.. now this is interesting.. maybe it has something to do with the underscore in the method name.. if I use names that have no underscores, it compiles just fine..  somebody verify this?
0
 
LVL 11

Expert Comment

by:rdrunner
ID: 8142554
Public Function CREATE_INSTANCE(ByVal sType As String) As Ioutput_script
   ' code
End Function
0
 
LVL 1

Expert Comment

by:Ysgrathe
ID: 8142555
the problem is that you have implemented the function with a different name than in the abstract class, just call them both the same EXACT name and you wont get that error.

you  have to implement all the functions from the abstract class, VB checks for this by making sure that all the names of functions are implemented

in the abstract you called it 'CREATE_INSTANCE'
in the implementation you called it 'IOutput_Script_Factory_CREATE_INSTANCE'
simply change the second one to 'CREATE_INSTANCE' and off you.

Hope this helps.
0
 

Author Comment

by:PMH4514
ID: 8142861
hmm.. the way I understood it - that's the proper way of implementing interfaces.. you name reference them with the interface name followed by underscore, and make it private..
hmm.. lemme find a MS example...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dninvb01/html/ivb0165.asp

I've also seen it like that in a design patterns book for VB.

look at the approach they take in the above example a ways down under the heading "Build the derived classes"

the concrete implementations are named like that - interfacename_methodname and are private (so that the "underscored name" as it were, didn't become a new part of the concrete class's interface.


and in fact this approach works, but not if the method names have an underscore..  

or maybe I'm still missing something..   I fully understand the concepts here, of OO and interface inheritance and where its appropriate, I'm just concerned with my syntax isn't working..
0
 

Author Comment

by:PMH4514
ID: 8142868
and as a follow up - if you open VB and create an abstract interface, and then open a new class, and say "Implements IYourInterface"

then in the (General) dropdown - if you select the implemented class - VB will spit out the methods using that same naming convention..
0
 

Author Comment

by:PMH4514
ID: 8241707
This question appears to have stalled.. I posted to Community support to close/kill the question off, they informed me to post said intent to this question and see if any participants have any objections.. so, please object, answer or let it go..
thanks
-Paul
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8272895
PAQ'd and all 80 points refunded.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
LVL 1

Expert Comment

by:tjeffryes
ID: 20887887
I had had an identical problem using VBA in MS Access 2003.

The problem IS the underscore in the name.  If you rename the property or method in the original class and remove the underscore, the resulting skeleton routines in the class that is implementing will have proper names and this will complile.

Tim Jeffryes
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…
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…
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…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 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