Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to declare interface for nested classes HELP!!!

Status
Not open for further replies.

grom2

Programmer
Oct 27, 2005
11
CA
I'm wanted to consume my vb.net assemblies (dll/tlb) from vb6. I can do this but an interface must be defined for the class. That works. But how do we define interfaces for a class with nested classes?

' Visual Basic
' This is the enclosing class, whose class declaration contains the nested
' class.
Public Class EnclosingClass
' This is the nested class. Its class declaration is fully contained
' within the enclosing class.
Public Class NestedClass
' Insert code to implement NestedClass.
End Class
' Insert code to implement EnclosingClass.
End Class

Thanks Glenn

 
As far as interfaces go I don't think it matters that the enclosing class has any nested classes. An interface definition can only hold method declarations. Any nested classes are by definition not methods, so you don't need to worry about them in your interface declaration. Any methods in any nested classes should only be accessible to the enclosing class, or accessible in the interface only via a method in the enclosong class that references the method in the nested class. Here's a link that explains it a little better:

[URL unfurl="true"]http://www.developer.com/lang/other/article.php/939411[/url]

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
I've read your response. The trouble i'm having is I can't create objects with nested classes from vb6. Try this, create the following class in vb.net. Then regasm it and try to create an object based on the nested class from vb6. Then try to declare the following. I can't. As soon as I run the project it tells me the type is undefined. Why?

dim obj as new EnclosingClass.NestedClass

' Visual Basic.net class
' This is the enclosing class, whose class declaration contains the nested
' class.
Public Class EnclosingClass
' This is the nested class. Its class declaration is fully contained
' within the enclosing class.
Public Class NestedClass
' Insert code to implement NestedClass.
End Class
' Insert code to implement EnclosingClass.
End Class
 
> rick said:
> How are you accessing your .Net assembly from VB6?

I use regasm on the dll then I add reference to the tlb in vb6. Early binding. But there's no reason why you couldn't use createobject with late binding.

dim obj as EnclosingClass.NestedClass

set obj = new EnclosingClass.NestedClass

or

dim obj as object
set obj = createobject("EnclosingClass.NestedClass")

Give this a try and you'll see what I mean.

Glenn


 
Yeah, I'm familiar with it, I just wanted to make sure you were using regasm to build the COM wrapper on the target machine.

My best answer is, you can't. Atleast, not in VB6. You may be best off not nesting the class and putting it in a namespace that creates the organization you are trying to achieve.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Hello

How would creating a namespace provide a solution? Can you give me an example of what your suggesting. The only option to me is to flatten the structure of the class so that it has no nested classes. What's your take?

Thanks,
Glenn
 
Now how would this change the declaraton in vb6? How does vb6 interpret namespaces? Also when you create a class from .net and then try to define an object based on that class from VB6 is it a requirement to create an interface. Without an interface vb6 won't let me create the object. Try this and let me know your results.

By the way thanks for the help as very few people have this level of knowlege.

Glenn
 
Nope, I don't have to create an interface.

I create my library as usual in .Net. I use regasm to create a COM wrapper (on every machine that uses the library from VB6). Then in VB 6 I add a reference to the .tlb file that regasm created. Then in code I can declare a variable with the standard Dim VarName as New ReferencedLibrary.ClassName

I've never tried using a namespace in VB, but I would think it is capable of using them.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
And you say you don't have to create an inteface to instantiate a class from vb6. Hmm, what am I doing wrong? If I don't create and interface vb6 complains that the type is not defined. Any when I try to access the propertys and methods etc. none list with intellisense. But I create an interface and all works well? Any ideas why that is? PS the reason i'm wanting to reverse engineer these classes to work in vb6 is we have our application designed in .net and i would like to expose some of the business logic as dll's for people to access using vbscript etc.

Thanks,
Glenn
 
I have the same thing in some of our code. A series of business logic that a 3rd party needed access to with out rewriting an entire data access layer and interface in VB6.

With out an interface they don't get intellisense, I'm not sure if that's an interface issue though. In our case, they only need access to a handful of public methods, so its easy enough to document with out having to provide intellisense.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Hello,

I tested the namespace theory. I doesn't work as expected.

Baically when you create a vb6 object the dot namespace does not display in intellisense. I tried just coding it thinking that it may just not expose the interface, still nothing.

Interesting that nested classes display at the root of intellisense with all the other classes and you can create an object based on a nested class. I was hoping to just copy/pasted vb.net code to vbs but it looks like I will have to revise the declaration to remove (flatten) the namespace from it and it will work. Give it a try and let me know your findings.

In the prefect world the vb.net dec would look like this

Dim obj as new assname.MyNamespace.MyThingy

The same dec in vb6 would look like this

Dim obj as new assname.MyThingy

namespace MyNamespace
Class MyThingy
End Class
end namespace

Namespace MyNameSpace.MySubNameSpace
Class MyOtherThingy
End Class
end namespace



Thanks
Glenn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top