Passing Objects to ActiveX Server

I have 3 projects: 1. The user interface. 2. The UI Business objects. 3. An ActiveX server.

I want to pass an object from the UI Business objects to the server. This server will not be known at run time, so I have to create the server with CreateObject. The server does have a reference to the UI Business objects, so I can declare variables of the type I am trying to pass. However, when I try to pass the object to the server I get error 13, type unknown. What am I doing wrong? Is it not possible to pass objects to servers created with Createobject?

The following is a code snippet from the UI Business object:

dim oServer as object

public sub Inialize(oObject as UIObject, sServerName as string)

set oServer = CreateObject("sServerName")
oServer.inialize oObject

end sub

The following is a code snippet from the server. Keep in mind the server has a reference to the UI Business Object project:

dim svrUIObject as UIObject

Public sub Inialize(oObject as UIObject)

set svrUIObject = oObject

end sub
LVL 1
MisledmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

halapayaCommented:
try passing the object as a variant type. so in ur server code

Public sub Inialize(oObject as Variant)
set svrUIObject = oObject
end sub

define the oObject as Variant not as UIObject.

This should work...
0
MisledmanAuthor Commented:
Thanks for your answer. However, I don't want to pass as variant if I can get out of it. Is that the only way?
0
amebaCommented:
No, it's not the only way.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

MisledmanAuthor Commented:
Tell me how to do it and I will award the points to you ameba. Changing the declarations to variant solves one problem but creates another. I get type mismatch when I references objects in the subordinate objects.
0
halapayaCommented:
ublic sub Inialize(oObject as UIObject)
set svrUIObject = oObject
end sub

here try passing it as byreference...
Public sub Inialize(byref oObject as UIObject)
0
amebaCommented:
So, you want your object(s) early bound.
Delete Inialize method in your server code. Use public variable instead:
Public svrUIObject as UIObject

In your UI Business object code, replace:
    oServer.inialize oObject
with
    Set oServer.svrUIObject = oObject

----------------------------
If server is not known at design time, this doesn't mean you have to declare it 'as object':
Dim oServer as Object
It can be early bound, even though it was created by CreateObject
    Dim oServer as IServer
    Set oServer = CreateObject("MyServer.clsMain")

For this to work, MyServer.clsMain must implement IServer interface:
- it must have line: Implements IServer
- you must provide interface (definition, or convention) to server developer.
----------------------------
I am not sure what is your concept, but it looks like you'll have circular references (in UIObject reference to Server and opposite) ...?
0
MisledmanAuthor Commented:
Halapaya: All objects passed in VB are by reference. That is the same thing.

Ameba: I thought you were on the right track, however, using an interface still doesn't work. When I try to use CreateObject and assign to the variable declared as the Interface class, I still get error 13, Type mismatch. I have implemented the interface and used all the propertys and methods in the interface.  Surely there is a way to do this.
0
amebaCommented:
I tested my first suggestion and it works. I think it addresses your error 13 problem.

My second suggestion - using Implements keyword - is just a hint to make the other variable early bound.
> from the UI Business object:
>dim oServer as object
I am not sure if you have problem with this variable. If it is, you'll need few things, so it will be good to see your interface class code and how do you use it.

See also:
How do I use the Implements keyword?
http://www.insteptech.com/VBOO.htm
0
MisledmanAuthor Commented:
Ameba, you were right after all. I was a dummy. I had a reference to the dll, not the project, from the server class. FYI, I instanced the server variable as the interface class. Then used createobject to make server and applied it to the interface variable. works fine. Answer the question again with thank you or something and I will award the points to you. Thanks.
0
amebaCommented:
OK! Thank you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.