Misledman
asked on
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
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
ASKER
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?
No, it's not the only way.
ASKER
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.
ublic sub Inialize(oObject as UIObject)
set svrUIObject = oObject
end sub
here try passing it as byreference...
Public sub Inialize(byref oObject as UIObject)
set svrUIObject = oObject
end sub
here try passing it as byreference...
Public sub Inialize(byref oObject as UIObject)
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.cls Main")
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) ...?
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.cls
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) ...?
ASKER
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.
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.
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
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
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Public sub Inialize(oObject as Variant)
set svrUIObject = oObject
end sub
define the oObject as Variant not as UIObject.
This should work...