Associating a Message Link with a Method

From RAD Studio
Jump to: navigation, search

Go Up to Interaction Diagram Procedures

Message links can be associated with the methods of the recipient class. The methods can be selected from the list of existing ones or can be created. This is done by two commands provided by the message context menu: Add and Choose method.

You can use the Operation field in the Object Inspector to rename the method. A dialog box appears asking if you want to create a new method or rename the old one.

Use the following techniques to associate a message link with a method (operation):

  1. Create a new method for an existing message link
  2. Associate an existing method with a message link
  3. Unlink a method

To create a new method for an existing message link:

  1. Create a message link between two objects. The recipient object must instantiate a class.
  2. On the context menu of the message link, choose Add. The submenu provides the choice of Method, Constructor or Destructor.

    Note: Destructors are available for classes in C++ projects only.

  3. From the submenu, choose the required operation type.

Tip: If the recipient object does not instantiate a class, the Add command is not available on the context menu. If the recipient object is associated with an interface, only methods can be associated with the message link.

Result: The new operation is created in the class of the recipient object. The message link is labeled with the operation name, according to the operation type:

If a Method is selected, the label is Method<n> ():return_type.

If a Destructor is selected, the label is ~<Classname>(). The Destructor option is disabled in the submenu of the Add command.

You can use the Operation field in the Object Inspector to create a new method in the classifier. For example, in the Operation field, you can enter method_name(parameter_types):return_type. Entering parameter_types is optional. If the method does not exist in the class, a dialog opens prompting you to create it. If the method already exists in the class, the message link is automatically set for that method.

To associate an existing method with a message link:

  1. Create a message link between two objects. The recipient object must instantiate a class.
  2. On the context menu of the message link, select Choose method. The submenu displays the list of operations of the recipient class.
  3. If you cannot find the required operation in the list, click More to reveal the next 20 methods (including inherited operations) of the recipient class.
  4. Select the required operation.

Result: The associated operation is selected from the list of available methods, constructor, or destructor.

If you choose to associate a different classifier for an object that is already instantiated with a classifier, all of the message links where the Operation property has been set are automatically saved as text unless the method signature matches another method signature within the newly-linked classifier.

To unlink a method:

  1. Select the message link.
  2. On the context menu of the message link, choose Unlink method.

Result: An association between the message link and the operation is removed. However, the operation is preserved in the recipient class.

If you unlink a classifier from an object and that object has incoming message links where the Operation property is set to a method of the unlinked classifier, a dialog opens prompting you to unlink the method from the message link or save it as text. Choosing the option to save as text places the Operation property in quotation marks and the operation displays in red on the diagram. The intent of this feature is to help users to preserve all of the signatures of any methods that have been linked to the message links. Upon instantiating the object with a class again, you can delete the quotation marks. This will open a dialog box prompting you to create the method if it does not exist in the linked classifier. A dialog box does not open if the signature of the method matches an existing method in the classifier.

See Also