?
Solved

Passing Objects to ActiveX Server

Posted on 2000-01-09
10
Medium Priority
?
144 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:Misledman
  • 4
  • 4
  • 2
10 Comments
 
LVL 3

Expert Comment

by:halapaya
ID: 2336116
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
 
LVL 1

Author Comment

by:Misledman
ID: 2336152
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
 
LVL 15

Expert Comment

by:ameba
ID: 2336259
No, it's not the only way.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 1

Author Comment

by:Misledman
ID: 2336300
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
 
LVL 3

Expert Comment

by:halapaya
ID: 2336368
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
 
LVL 15

Expert Comment

by:ameba
ID: 2336393
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
 
LVL 1

Author Comment

by:Misledman
ID: 2339471
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
 
LVL 15

Expert Comment

by:ameba
ID: 2339575
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
 
LVL 1

Author Comment

by:Misledman
ID: 2354326
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
 
LVL 15

Accepted Solution

by:
ameba earned 400 total points
ID: 2354483
OK! Thank you.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month6 days, 9 hours left to enroll

593 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