Chapter 3 Getting Started with Objects Manipulation Using Scripts
The following example illustrates how you can retrieve an object by its code in the model
' Call a function that is implemented just after in the script
Dim FoundIntf, FoundClass
Set FoundIntf = RetrieveByCode(ExistingModel, PDOOM.Cls_Interface, "custIntf")
Set FoundClass = RetrieveByCode(ExistingModel, PDOOM.Cls_Class, "cust")
If (not FoundIntf is nothing) and (not FoundClass is Nothing) Then
output "The class and interface objects have been successfully retrieved by their code"
End If
' Implement a method that retrieve an object by code
' The first parameter is the root folder on which the research begins
' The second parameter is the kind of object we are looking for
' The third parameter is the code of the object we are looking for
Function RetrieveByCode(RootObject, ObjectKind, CodeValue)
' Test root parameter
If RootObject is nothing Then
Exit Function ' Root object is not defined
End If
If RootObject.IsShortcut() Then
Exit Function ' Root object is a shortcut
End If
If not RootObject.IsKindOf(Cls_BaseFolder) Then
Exit Function ' Root object is not a folder
End If
' Loop on all objects in folder
Dim SubObject
For Each SubObject in RootObject.Children
If SubObject.IsKindOf(ObjectKind) and SubObject.Code = CodeValue Then
Set RetrieveByCode = SubObject ' Initialize return value
Set SubObject = Nothing
Exit Function
End If
Next
Set SubObject = Nothing
' Recursive call on sub-folders
Dim SubFolder
For Each SubFolder in RootObject.CompositeObjects
If not SubFolder.IsShortcut() Then
Dim Found
Set Found = RetrieveByCode(SubFolder, ObjectKind, CodeValue)
If not Found Is Nothing Then
Set RetrieveByCode = Found ' Initialize return parameter
Set Found = Nothing
Set SubFolder = Nothing
Exit Function
End If
End If
Next
Set SubFolder = Nothing
End Function
Copyright (C) 2007. Sybase Inc. All rights reserved. |
![]() |