Chapter 3 Notions de base relatives à la manipulation d'objets à l'aide de scripts
Dans l'exemple suivant, nous allons manipuler les objets dans une collection en créant des objets règles de gestion puis en les attachant à un objet classe. Pour cela, nous allons :
If (not ExistingModel Is Nothing) and (not FoundClass Is Nothing) Then ' We are going to create business rule objects and attached them to the class ' Create first the business rule objects Dim Rule1, Rule2 Set Rule1 = ExistingModel.BusinessRules.CreateNew() Set Rule2 = ExistingModel.BusinessRules.CreateNew() If (not Rule1 is Nothing) And (not Rule2 Is Nothing) Then output "Business Rule objects have been successfully created" ' Initialize rule attributes Rule1.SetNameAndCode "Mandatory Name", "mandatoryName" Rule1.ServerExpression = "The Name attribute cannot be empty" Rule2.SetNameAndCode "Unique Name", "uniqueName" Rule2.ServerExpression = "The Name attribute must be unique" ' Retrieve the first object in the class attributes collection Dim FirstAttr, AttrColl Set AttrColl = FoundClass.Attributes If not AttrColl is Nothing Then If not AttrColl.Count = 0 then Set FirstAttr = AttrColl.Item(0) End If End If Set AttrColl = Nothing If not FirstAttr is Nothing Then output "First class attribute successfully retrieved from collection" ' Add Rule1 at end of attached rules collection FirstAttr.AttachedRules.Add Rule1 ' Add Rule2 at the beginning of attached rules collection FirstAttr.AttachedRules.Insert 0, Rule2 ' Move Rule2 at end of collection FirstAttr.AttachedRules.Move 1, 0 ' Remove Rule1 from collection FirstAttr.AttachedRules.RemoveAt 0 Set FirstAttr = Nothing End If End If Set Rule1 = Nothing Set Rule2 = Nothing End If
Copyright (C) 2006. Sybase Inc. All rights reserved. |
![]() |