CreateObject vs. New 
Author Message
 CreateObject vs. New

I have a large client-server application written entirely in Visual Basic. I
am running into errors in MyServer.ClassB.someMethod on the lines that say

Set Myobj = CreateObject("MyServer.ClassA")

But if I say,

Set MyObj = New MyServer.ClassA

 it works. Which way should I be doing it?  I know the latter method is
early binding and it's more efficient at runtime.  But will it have
ramifications for multithreading?

Thanks.

--
Daniel Wilson, BSCS, MCSE
CompuSoft Solutions and The Worthwhile Company
www.worthwhile.com
Your complete e-business solution partners.
Phone: 864-233-9029 Fax: 509-757-5264



Sat, 18 Sep 2004 05:12:08 GMT  
 CreateObject vs. New
Actually, the type of variable tha Myobj is declared as determines whether
it's late binding or not (Object = late binding).  The 2nd method saves one
registry lookup to convert a ProgId to a CLSID, so if you already have a
reference to the class the 2nd method would be the way to go.  Apparently,
the ProgId you're specifying in the first call isn't the ProgId of the class
you're attempting to create.

-------------------------------------------------
Automate your software builds with Visual Build
http://www.visualbuild.com


Quote:
> I have a large client-server application written entirely in Visual Basic.
I
> am running into errors in MyServer.ClassB.someMethod on the lines that say

> Set Myobj = CreateObject("MyServer.ClassA")

> But if I say,

> Set MyObj = New MyServer.ClassA

>  it works. Which way should I be doing it?  I know the latter method is
> early binding and it's more efficient at runtime.  But will it have
> ramifications for multithreading?

> Thanks.

> --
> Daniel Wilson, BSCS, MCSE
> CompuSoft Solutions and The Worthwhile Company
> www.worthwhile.com
> Your complete e-business solution partners.
> Phone: 864-233-9029 Fax: 509-757-5264



Sat, 18 Sep 2004 06:37:39 GMT  
 CreateObject vs. New

Quote:

> I have a large client-server application written entirely in Visual Basic. I
> am running into errors in MyServer.ClassB.someMethod on the lines that say

> Set Myobj = CreateObject("MyServer.ClassA")

> But if I say,

> Set MyObj = New MyServer.ClassA

>  it works. Which way should I be doing it?  I know the latter method is
> early binding and it's more efficient at runtime.  But will it have
> ramifications for multithreading?

CreateObject might be a little slower, but early vs. late binding
has nothing to do with it.  The binding comes from MyObj's data
type.  If MyObj is defined As Object or As Variant, then and only
then are you using late binding!  CreateObject is different from
New in the following ways:

Friend methods and properties will be unavailable

New will create instances within the current threading context if
it possibly can (significant mainly within ActiveX EXE code)

MTS/COM# will "hiccup" if clients use New instead of CreateOject as
THE LORD Billweh intended

MTS/COM# will b0rk if server components use CreateObject instead of
ObjectContext.CreateInstance as THE LORD Billweh commandeth

(MTS/COM# will /probably/ b0rk if server code calls New instead of
ObjectContext.CreateInstance as THE LORD Billweh proclaimeth)

Other microslopware might also be sensitive to CreateObject vs. New

--
Joe Foster <mailto:jlfoster%40znet.com>  Sacrament R2-45 <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Sat, 18 Sep 2004 09:41:01 GMT  
 CreateObject vs. New

Quote:
> MTS/COM# will "hiccup" if clients use New instead of CreateOject as
> THE LORD Billweh intended

> MTS/COM# will b0rk if server components use CreateObject instead of
> ObjectContext.CreateInstance as THE LORD Billweh commandeth

> (MTS/COM# will /probably/ b0rk if server code calls New instead of
> ObjectContext.CreateInstance as THE LORD Billweh proclaimeth)

> Other microslopware might also be sensitive to CreateObject vs. New

> --
> Joe Foster <mailto:jlfoster%40znet.com>  Sacrament R2-45

<http://www.xenu.net/>
Quote:
> WARNING: I cannot be held responsible for the above        They're
coming  to
> because  my cats have  apparently  learned to type.        take me away,

ha ha!

ok, ur cats can type, but they type not the absolute truth



Sat, 18 Sep 2004 19:16:22 GMT  
 CreateObject vs. New

Quote:

> > MTS/COM# will "hiccup" if clients use New instead of CreateOject as
> > THE LORD Billweh intended

> > MTS/COM# will b0rk if server components use CreateObject instead of
> > ObjectContext.CreateInstance as THE LORD Billweh commandeth

> > (MTS/COM# will /probably/ b0rk if server code calls New instead of
> > ObjectContext.CreateInstance as THE LORD Billweh proclaimeth)

> > Other microslopware might also be sensitive to CreateObject vs. New
> ok, ur cats can type, but they type not the absolute truth

Care to elaborate, please?

--
Joe Foster <mailto:jlfoster%40znet.com>   L. Ron Dullard <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Sun, 19 Sep 2004 04:10:36 GMT  
 CreateObject vs. New




Quote:

> > > MTS/COM# will "hiccup" if clients use New instead of CreateOject as
> > > THE LORD Billweh intended

MTS: u will get strange behaviour when creating _configured_ components from
configured components if u use new or createobject
COM+: u will get strange behaviour when creating _configured_ components
from configured components  if u use new for classes in the same dll

Quote:
> > > MTS/COM# will b0rk if server components use CreateObject instead of
> > > ObjectContext.CreateInstance as THE LORD Billweh commandeth
> > > (MTS/COM# will /probably/ b0rk if server code calls New instead of
> > > ObjectContext.CreateInstance as THE LORD Billweh proclaimeth)

MTS: u have to use CreateInstance when creating _configured_ components from
configured components
COM+: CreateInstance is obsolete

Quote:

> > > Other microslopware might also be sensitive to CreateObject vs. New

go to my web site and read the article about this topic

Quote:
> Care to elaborate, please?

--
Steffen Ramlow
Enterprise Development: http://www.dev-purgatory.org/


Sun, 19 Sep 2004 14:57:32 GMT  
 CreateObject vs. New

Quote:





> > > > MTS/COM# will "hiccup" if clients use New instead of CreateOject as
> > > > THE LORD Billweh intended

> MTS: u will get strange behaviour when creating _configured_ components from
> configured components if u use new or createobject
> COM+: u will get strange behaviour when creating _configured_ components
> from configured components  if u use new for classes in the same dll

And if there's absolutely *any* doubt /whatsoever/, use CreateObject anyway?

Quote:
> > > > MTS/COM# will b0rk if server components use CreateObject instead of
> > > > ObjectContext.CreateInstance as THE LORD Billweh commandeth
> > > > (MTS/COM# will /probably/ b0rk if server code calls New instead of
> > > > ObjectContext.CreateInstance as THE LORD Billweh proclaimeth)

> MTS: u have to use CreateInstance when creating _configured_ components from
> configured components

And if there's absolutely *any* doubt /whatsoever/, use CreateInstance anyway?

Quote:
> COM+: CreateInstance is obsolete

And if there's absolutely *any* doubt /whatsoever/, use CreateObject anyway?

Quote:
> > > > Other microslopware might also be sensitive to CreateObject vs. New

> go to my web site and read the article about this topic

Naah, surely Micro$haft will just pull the rug out again real soon anyway?

--
Joe Foster <mailto:jlfoster%40znet.com>  Wanna buy a Bridge? <http://xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Thu, 23 Sep 2004 03:16:53 GMT  
 CreateObject vs. New
r u sure that u know what u r talking?

--
Steffen Ramlow
Enterprise Development: http://www.dev-purgatory.org/



Quote:
> And if there's absolutely *any* doubt /whatsoever/, use CreateObject
anyway?
> And if there's absolutely *any* doubt /whatsoever/, use CreateInstance
anyway?
> And if there's absolutely *any* doubt /whatsoever/, use CreateObject
anyway?
> Naah, surely Micro$haft will just pull the rug out again real soon anyway?



Thu, 23 Sep 2004 19:55:39 GMT  
 CreateObject vs. New

Quote:

> r u sure that u know what u r talking?

Well, perhaps there will be no problems if the sets of components
that are "inside" and "outside" MTS/COM+ are carved in stone, in
perpetuity, forever, eternally, and will certainly never, ever
evolve in any way over anything even remotely resembling a "full
development life-cycle".  Otherwise, if anything is changed ever,
the conditions are ripe for bugs and slowdowns caused by using
New when one should have used CreateObject, CreateObject when one
should really have used New or CreateInstance, etc. etc. etc. ...

--
Joe Foster <mailto:jlfoster%40znet.com>   L. Ron Dullard <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Fri, 24 Sep 2004 04:58:39 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. CreateObject vs. New

2. CreateObject vs. New operator.

3. CreateObject VS New

4. CreateObject vs New

5. New vs. CreateObject

6. strange problem: createobject vs new

7. CreateObject vs New, with Implements ObjectControl

8. New vs. CreateObject

9. New Vs CreateObject

10. CreateObject vs New

11. CreateObject vs New keyword in COM+

12. new ActiveXObject() vs. Server.CreateObject()

 

 
Powered by phpBB® Forum Software