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 Scripting PowerDesigner.