|
-
Aug 31st, 2003, 11:34 PM
#1
Thread Starter
Member
CreateObject Vs New?
I am a new VB programmer. I would Like to know the difference between
CreateObject function and New Keyword.
Please tell me in detail.
Thanks in advance.
-
Sep 2nd, 2003, 09:49 AM
#2
Frenzied Member
New forces the compiler to verify the existence of the COM server file, and it binds the object at compile time. This is called early binding. It is faster because the overhead of object creation happens during compile & link.
CreateObject binds the COM server during runtime. The compiler has no idea if the COM server even exists. This is called late binding. This is slower for the creation of the first object in the class than early binding. It is also more error-prone, because the VB program has no way to know if the external COM object exists until the program attempts to create the object.
Suggestion : get and read VB COM by Lewis Thomas
-
Sep 2nd, 2003, 11:14 AM
#3
Frenzied Member
Don't forget that 'New' will use the VB runtime for all marshalling and transactional contexts if the class is in the same VB Project whilst CreateObject will always use SCM for this regardless of class location.
-
Sep 2nd, 2003, 11:16 AM
#4
Frenzied Member
CreateObject binds the COM server during runtime. The compiler has no idea if the COM server even exists. This is called late binding. This is slower for the creation of the first object in the class than early binding. It is also more error-prone, because the VB program has no way to know if the external COM object exists until the program attempts to create the object.
Not strictly true: If you declare (Dim) the objects IUnknown interface (or IDispatch if you have to) and then use CreateObject you will use early binding.
Create Object is slower because it performs a registry lookup of the ProgId, and then uses the SCM to instantiate the object.
-
Sep 2nd, 2003, 02:52 PM
#5
Frenzied Member
Y: You're correct-- but this guy is new - assume he doesn't know IUknown from IDispatch from a vtable.
-
Sep 3rd, 2003, 01:43 AM
#6
Frenzied Member
-
Sep 5th, 2003, 07:44 AM
#7
Thread Starter
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|