Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
New or CreateObject???
Message
 
To
01/06/2001 07:08:14
General information
Forum:
Visual Basic
Category:
Other
Miscellaneous
Thread ID:
00513525
Message ID:
00513696
Views:
13
>>What's the difference between using New or CreateObject?.
>>Is there performance reasons or rules about use one of them?.
>>
>>Your help will be very useful!!!
>>
>>Thanks guys!!!!
>
>You can reference an object using early or late binding.
>Using CreateObject, you use late binding. VB does not know of the object until the code is executed. VB can't use Intellisence to display the properties and methods in the code window and cannot check your code. Another downside to late binding is that it is slower. One benefit is that since there's no reference to the object, if it does not exist on the user's PC, your app can run and you can trap the error when trying to create the object. Another usefull use of late binding is that you can distribute new version of your objects without recompile your app.
>
>When you put a reference to an object and use declare a variable with the New keyword, you use early binding. Benefits are: a lot faster then late binding, code checking, Intellisence.

Sorry Guy but I have to contradict you on some points. Sorry again.

Using CreateObject doesn't always means that you are late bound. To be late bound, your variable must be declared as Object. You can have a variable of a specific type and still use the CreateObject statement.

New can be faster because it is caching reference to objects. If you instantiate more than one instance of the same object, New will be faster (CreateObject always return to the Registry to get the reference).

With CreateObject (in VB6), you can specify the server name in the second parameter which help when using DCOM.

CreateObject can also have a string variable as the first parameter (you then gain some flexibility).
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform