Solved

CREATEOBJECT WITHIN A PROJECT

Posted on 2000-04-13
9
276 Views
Last Modified: 2012-05-04
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
Comment
Question by:leecarroll
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 6

Expert Comment

by:Marine
ID: 2713794
If not why not create a Group Project and do it from there. This  will garantee it will work.
0
 

Author Comment

by:leecarroll
ID: 2713905
Adjusted points from 100 to 200
0
 

Author Comment

by:leecarroll
ID: 2713906
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 15

Accepted Solution

by:
ameba earned 200 total points
ID: 2714259
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
 
LVL 15

Expert Comment

by:ameba
ID: 2714272
Sample:
   Dim x As clsCustomer
   Set x = CreateObject("Project1.clsCustomer")
   x.Name = "John"  ' early bound call!
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2715126
"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
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 2715401
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
 

Author Comment

by:leecarroll
ID: 2717707
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
 
LVL 15

Expert Comment

by:ameba
ID: 2717928
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

738 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