jen
January 19th, 2000, 01:54 AM
Hi
I'm really confused about when to use what.
I'm writing an app to be distributed. It exist on a thin client so I want to use DCOM (CreateObject(ClassName,ServerName)) to create it on the server. So what about CreateInstance? When do I use it? I have a feeling that I have mixed everything and would be sooooo grateful if somebody could help me sort this out.
Thanks
Jen
JimmyT
January 19th, 2000, 08:38 PM
I haven't used MTS, yet, but I do have a few good resources that may answer your question.
This is from Chapter 5 of the MCSD VB 6 Distributed Applications Exam Preparation Guide:
"You can create an object in Visual Basic using CreateObject, New, and CreateInstance. You may wonder why you should use CreateInstance for the ObjectContext object when you can call CreateObject or use New keyword to create objects.
Although using New keyword to create an object is better than calling CreateObject, New keyword creates the object internally instead of using COM services to create it. If the object created is an MTS object, this yields undesirable effects because MTS uses COM services to host its objects. Thus, if COM is not used to create the object, MTS cannot host the object. So you have to use CreateObject call to create the object, which uses COM services to create it.
Even though you have created the MTS object by using either New or CreateObject, the object does not inherit its context form the caller. Which means that it cannot participate in the existing transaction, even if its transaction attribute is set to Requires a transaction or Supports transactions. Because it is not part of the same activity, it does not have access to security information.
If CreateInstance is used to create an MTS object, that object can participate in the existing transaction, and it inherits its context from the caller (this includes the current activity, security information, and current transaction)."
In a nutshell, it seems that if you want to use the object in the current transaction, use CreateInstance. If you don't, then you can use CreateObject.
Good Luck...