Project members: Slot method

With a slot method member you can implement the logic to execute when the slot method receives a signal. This approach follows the signal-slot paradigm where two objects communicate without having to take care of each other identity. The slot methods are represented in Composer by following bricks:

Every slot method has a body containing its implementation code. The code is expressed in the platform-independent Chora syntax. Within the code you can evaluate and modify variables, perform calculations, call other methods, etc.

A slot method can be defined within a class or class variant only. If one class is derived from another class, all methods implemented in the ancestor classes are inherited implicitly. In the derived class the inherited methods can be overridden and modified with new implementation.

In order to preserve the clarity, all methods inherited from a base class but not overridden in the actual class are not shown as bricks in the Composer. The Inspector, in turn, shows always the complete list including all inherited members. If you are looking for a particular inherited method, use the Inspector for this purpose. Please note, inherited but not overridden methods are shown in Inspector with gray thin font:

Inherited but not overridden slot methods appear only in the Inspector window. They are shown with thin gray font.

If an inherited method has been overridden, Inspector shows it with dark gray font. Additionally, overridden methods appear as bricks in the Composer window. You can distinguish easily, whether a method is overridden or whether it is new by considering the font color in its brick. New methods are shown with black font. Overridden methods, in turn, with gray font:

Overridden methods appear in Inspector with dark gray font. They are also shown as bricks in Composer, again with gray font.

Add new slot method

First switch to the Composer page for the respective class or class variant definition, where you want to add the new slot method.

Then, in the Gallery window, ensure that the folder Chora is opened.

Look in the folder for the template named Slot Method.

With the mouse, select the template and drag it into the Composer.

Drop the template within the Composer.

Adding a new slot method.

Name the slot method

First ensure, that the slot method is selected.

Press the key F2 or select the menu item EDITRename ....

Enter the new name in the Inspector window.

Slot methods have a local character - they can be accessed only in context of an instance of the class, in which they are defined. To address a slot method, you use its name. Please note, the name of an inherited slot can't be changed retrospectively in the derived class.

Edit the method in Editor window

The body of a slot method is edited in the Code Editor window. For this purpose:

First ensure, that the slot method is selected.

Press the key ENTER ...

... or double click on the slot method with the mouse.

In the Code Editor you implement the method by using Chora statements and expressions.

Please note, before you can edit an inherited method, you have to override it first.

Use the implicit parameter sender

Slot methods are invoked in response to signals received from other objects. At the execution time, the identify of the sender object is passed on to the slot method in the hidden parameter sender. In your implementation, you can evaluate this parameter and e.g. distinguish between various sender objects.

Please note the description of postsignal and idlesignal statements regarding the behavior when multiple signals (and thus multiple sender objects) are recorded to one and the same slot method.

Duplicate an existing slot method

You can create any number of copies of an already existing slot method.

First ensure, that the method is selected.

Press the keys CtrlC and CtrlV in succession ...

... or hold the key Ctrl pressed while you drag and drop the selected method.

Finally rename the just duplicated method.

Override an inherited slot method

In order to provide new implementation for an inherited method, you have to override it explicitly:

First ensure, that the slot method is selected in the Inspector window.

Drag and drop the selected method from the Inspector to the Composer window while holding the keys CtrlShift pressed.

Finally you can open the method for editing.

Overriding an inherited slot method.

Perform a super() call

When you override an inherited method, it is often convenient to invoke from the new implementation the inherited version of the method. This can be achieved by calling the pseudo method super(). The pseudo method expects the sender parameter to by passed in its unique argument. For example:

// First at all, let the base class version of the method do // its work super( sender ); // Then continue in the overridden method SomeTextView.Visible = true;

Please note, starting with version 13 each newly overridden method contains code to perform the super() invocation by default. If it is not desired, you can select and delete the code fragment.

Revert to inherited slot method

If you want to revert an overridden slot method to its original inherited implementation, delete it simply. Thereupon, its brick disappears from the Composer and the Inspector shows the method name with thin font again.

Use the slot method

To send signals to a slot method you use the statements signal, postsignal or idlesignal. A slot method can also be registered as notification observer. In this case the slot method is invoked when the observer is notified.

If the identity of the affected slot method is well known, you can send the signals directly to it by using its name. But usually, you will send the signals indirectly by using a reference to a slot method. For this purpose the data type slot is available. You can, for example, create variables and store there references to slot methods you want to signal later. For example:

// Send a signal directly to slot method defined in the current // class. signal SomeKnownSlotMethod; // Get a reference to a slot method existing in a foreign object // and store it in a variable ... var slot theVar = SomeObject.SomeSlotMethod; [...] // ... later send a signal to the slot method indirectly. signal theVar;

Control the code generation

With the attribute Generator you can selectively control, whether the method should be taken in account during the code generation or not. Configuring this attribute with the value false will exclude the method from your project unless the corresponding method is explicitly involved within a Chora expression.

Delete a slot method

First ensure, that the slot member is selected.

Press the key DEL or select the menu item EDITDelete.

Please note, inherited methods can't be deleted. However, if a method is overridden you can delete this overriding.

Attributes of a slot method

The following table shows the complete list of attributes provided by the slot method member:

Attribute name

Short description

Brick

Determines the position and the size of a slot method brick within the Composer window.

Description

Contains the description for the slot method member.

Generator

Controls the code generation for the affected slot method member.

Native

Specifies the kind of language the corresponding method is implemented in.