Chapter 3 Notions de base relatives à la manipulation d'objets à l'aide de scripts
Il est recommandé de créer un objet directement à partir de la collection à laquelle il appartient afin d'obtenir immédiatement un état valide de l'objet. En revanche, vous créez certes l'objet, mais pas son symbole.
Vous pouvez également utiliser la méthode suivante : CreateObject(ByVal Kind As Long, ByVal ParentCol As String = "", ByVal Pos As Long = -1, ByVal Init As Boolean = -1) As BaseObject
If not ExistingModel is Nothing Then ' Call the CreateNew() method on the collection that owns the object Dim MyClass Set MyClass = ExistingModel.Classes.CreateNew() If MyClass is nothing Then msgbox "Fail to create a class", vbOkOnly, "Error" ' Display an error message box Else output "The class objects has been successfully created" ' Display a message in the application output window ' Initialize its name and code using a specific method ' that ensures naming conventions (Uppercase or lowercase constraints, ' invalid characters...) are respected and that the name and code ' are unique inside the model MyClass.SetNameAndCode "Customer", "cust" ' Initialize other properties directly MyClass.Comment = "Created by script" MyClass.Stereotype = "MyStereotype" MyClass.Final = true ' Create an attribute inside the class Dim MyAttr Set MyAttr = MyClass.Attributes.CreateNew() If not MyAttr is nothing Then output "The class attribute has been successfully created" MyAttr.SetNameAndCode "Name", "custName" MyAttr.DataType = "String" Set MyAttr = Nothing End If ' Reset the variable in order to avoid memory leaks Set MyClass = Nothing End If End If
If not ExistingModel is Nothing Then ' Create a package first Dim MyPckg Set MyPckg = ExistingModel.Packages.CreateNew() If not MyPckg is Nothing then output "The package has been successfully created" MyPckg.SetNameAndCode "All interfaces", "intf" ' Create an interface object inside the package Dim MyIntf Set MyIntf = MyPckg.Interfaces.CreateNew() If not MyIntf is Nothing then output "The interface object has been successfully created inside the package" MyIntf.SetNameAndCode "Customer Interface", "custIntf" Set MyIntf = Nothing End If Set MyPckg = Nothing End If End If
Copyright (C) 2007. Sybase Inc. All rights reserved. |
![]() |