Operatore New

Usate l'operatore New per istanziare oggetti di tipi definiti dall'utente, così come servizi Uno, strutture ed enumerazioni.

Sintassi:

Dim oObj as New ObjectType

oObj = New ObjectType

note

Potete usare l'operatore New sia durante la dichiarazione delle variabili, sia in un'operazione di assegnazione.


Esempio:

L'esempio seguente usa l'operatore New per creare un'istanza di una struttura Uno PropertyValue.


    ' Istanziazione dell'oggetto durante la dichiarazione della variabile
    Dim oProp1 as New com.sun.star.beans.PropertyValue
    oProp1.Name = "Some name"
    oProp1.Value = 100
    ' Lo stesso effetto può essere ottenuto con un'assegnazione
    Dim oProp2 as Object
    oProp2 = New com.sun.star.beans.PropertyValue
    oProp2.Name = "Other name"
    oProp2.Value = 200
  
tip

L'operatore New è opzionale se è impostata l'opzione Compatible.


L'esempio sottostante crea un nuovo tipo Student e istanzia un oggetto di questo tipo:


    Type Student
        FirstName as String
        Program as String
    End Type
    
    Sub TestObjects
        Dim oStudent1 as New Student
        oStudent1.FirstName = "John"
        oStudent2.Program = "Computer Science"
    End Sub
  

Sosteneteci!