Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Instantiating variables
Message
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00406736
Message ID:
00406974
Vues:
18
>>>>Dim oBizObj As New myClass
>>>
>>> Never use the above, use the code below, there are almost no good reasons to use the above:
>>>
>>>>or
>>>>Dim oBizObj As myClass
>>>>Set oBizObj = New myClass

>>
>>Thanks. Never heard that before, can you explain?
>
>When using the first syntax, VB delays instanciation until the first use of the class. Let me demonstrate it:
>
>If you write:
>
dim x as new class1
>x.prop1 = "value"
>x.prop2 = "value"
>x.method
>
>VB will compile it this way (to instantiate the class on the first use):
>
dim x as class1
>if x is nothing then set x = new class1
>x.prop1 = "value"
>if x is nothing then set x = new class1
>x.prop2 = "value"
>if x is nothing then set x = new class1
>x.method
>
>Calling yourself the New operator (like your second syntax) allows VB not to execute more statements!
George
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform