Chapter 4 Extending your Models with Profiles


Methods (Profile)

Methods allow you to perform actions on objects. They are written in VBScript, and are invoked by other profile components, such as menu items (see Menus (Profile)) or form buttons (see Forms (Profile)).

The following example method, created in the Class metaclass, converts classes into interfaces. It copies class basic properties and operations, deletes the class (to avoid namespace problems), and creates the new interface.

Note that this script does not deal with other class properties, or with interface display, but a method can be used to launch a custom dialog box to ask for end-user input before performing its action (see Example: Creating a dialog box launched from a menu).

Sub %Mthd%(obj)
   ' Convert class to interface

   ' Copy class basic properties
   Dim Folder, Intf, ClassName, ClassCode
   Set Folder = obj.Parent
   Set Intf = Folder.Interfaces.CreateNew
   ClassName = obj.Name
   ClassCode = obj.Code
   Intf.Comment = obj.Comment
   
   ' Copy class operations
   Dim Op
   For Each Op In obj.Operations
      ' ...
      Output Op.Name
   Next

   ' Destroy class
   obj.Delete

   ' Rename interface to saved name
   Intf.Name = ClassName
   Intf.Code = ClassCode
End Sub

For detailed information about using VBScript in PowerDesigner, see the Scripting PowerDesigner chapter.

Steps To create a method:

  1. Right-click a metaclass, stereotype or criterion and select New→Method.
  2. Enter a name and a comment to describe the method.
  3. Click the Method Script tab, and enter the VBscript. If appropriate, you can reuse functions on the Global Script tab.

    By default, this tab contains the following skeleton script:

    Sub %Method%(obj)
        ' Implement your method on <obj> here
    End Sub


    %Method% is a concatenation of the name of the resource file, the metaclass (and any stereotype or criterion), and the name of the method itself defined in the General tab. If any of these names contains an empty space, it is replaced by an underscore.
  4. Click Apply.

 


Copyright (C) 2008. Sybase Inc. All rights reserved.