Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

CREATEOBJECT WITHIN A PROJECT

Can you use createobject to instantiate an Object from a server class which is in the same project as the client class ? If you can, then how. (Note I do not want to use the new key word)
0
leecarroll
Asked:
leecarroll
1 Solution
 
MarineCommented:
If not why not create a Group Project and do it from there. This  will garantee it will work.
0
 
leecarrollAuthor Commented:
Adjusted points from 100 to 200
0
 
leecarrollAuthor Commented:
The two classes will live in the same component, so they can't be in a different project. (I've read that you should use createobject within a component if you are going to use mts and you wish the object to have an object context, new does not cut the mustard as it does not use com.) Is my understanding of MTS at fault here, I feel that i'm missing something. I know i've just widen the question with this comment so i'll up the points
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
amebaCommented:
You cannot do this in 'standard exe' project type.
Change project type to ActiveX EXE and then it will work.

When you change project type, you'll perhaps need 'Sub Main' for startup. In 'Sub Main' call your main form.

From VB documentation for CreateObject:
"Note   The CreateObject function cannot be used on classes whose Instancing property is Private or PublicNotCreatable. The New operator can be used on any class."
0
 
amebaCommented:
Sample:
   Dim x As clsCustomer
   Set x = CreateObject("Project1.clsCustomer")
   x.Name = "John"  ' early bound call!
0
 
caraf_gCommented:
"in the same project"

WHY? You're guaranteed to have a reference as it's in the same project, so just use the New keyword.

There is absolutely *NO* need to use MTS for communication between objects in the same project. Just use globals or appropriate methods and properties to achieve your goal.

Hm.... perhaps I'm missing something?
0
 
corvanderlindenCommented:
If you are using MTS, you have to use an ActiveX DLL.

MTS heavily relies on COM.

Using New to create an Object that is part of the same project will bypass COM
CreateObject always uses COM.

New will use COM if you are creating an object in a different project

0
 
leecarrollAuthor Commented:
All the comments are pretty good but Ameba got it spot on. To use Createobject the object has to be externally creatable !! Thats what i was missing.
Cheers Lee
0
 
amebaCommented:
to caraf_g
>"in the same project"
>WHY?

It is good idea to start with a single project. This makes debugging easier/faster.
When things are prototyped, you can split and organize components.
0

Featured Post

Independent Software Vendors: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now