MessageArguments
¶
MessageArguments is the base class for arguments passed in messages. An instance of MessageArguments together with an instance of MessageType forms a Kanzi message. In Kanzi, when you dispatch a message, you dispatch a message of a certain type with arguments.
MessageArguments class allows you to create a derived class where you can specify your own specialized arguments. You can also link a MessageType to a specialized message arguments type. Use MessageType.newMessageArguments() API to get specialized MessageArguments class for a specific MessageType.
Use MessageArguments.createMessageArgumentsClass() API to define your own specialized message arguments in Lua. For example, this way you can define message types in your project. This is optional, since you can instantiate MessageArguments directly and access arguments values using MessageArguments.setArgument() and MessageArguments.getArgument() API. You can link specialized MessageArguments types with the corresponding MessageType and define convenient getters and setters for message arguments.
local message = ParallelActivityHost2D.DeactivateActivityMessageMessage
local arguments = message:newMessageArguments()
arguments:setActivationPathProperty(".")
You can link a message type with only one type of message arguments, but you can use a certain type of message arguments with multiple message types.
createMessageArgumentsClass() | Defines a specialized MessageArguments class |
new() | Constructor for MessageArguments class |
setArgument() | Sets the value of the argument |
getArgument() | Returns the value of an argument |
getSource() | Returns the source node for a message |
setHandled() | Sets the handling status for a message |
isHandled() | Returns whether the message is handled |
Defines a specialized MessageArguments class.
To define a specialized message arguments class, call this function with the Lua table that contains specific message arguments.
Keys of this table are the Lua names of the arguments and the values must contain their property types.
You can link the returned class to the corresponding MessageType, or you can instantiate it using the new()
method. The class inherits
all message arguments that you pass to this function and defines getters and setters for arguments
in the form get<ArgumentName>()
and set<ArgumentName>(value)
.
-- Define a specialized message arguments class with the arguments (properties) from the project.
DemoArguments = MessageArguments.createMessageArgumentsClass({
NewPropertyType = PropertyType:new("project.NewPropertyType")
})
-- Instantiate the class.
local arguments = DemoArguments:new()
-- Use setters and getters to access the values of arguments.
arguments:setNewPropertyType(42)
local value = arguments:getNewPropertyType()
-- Or access arguments by their property type.
arguments:setArgument(DemoArguments.NewPropertyType, 42)
propertyTypes | (table) | The table with the the list of property types that defines the arguments. |
(MessageArguments) | The specialized MessageArguments class. |
Constructor for MessageArguments class. Creates an instance of the basic MessageArguments class. You can use this class to send messages. Use MessageArguments.setArgument() or MessageArguments.getArgument() to access arguments whithin the specific instance of the basic MessageArguments class.
(MessageArguments) | The instance of basic MessageArguments class. |
Sets the value of the argument.
-- Define the argument property types.
BrushProperty = PropertyType:new("project.BrushProperty")
-- Instantiate message arguments class.
local arguments = MessageArguments:new()
-- Set the argument value.
local brushResource = ColorBrush:create("Brush")
arguments:setArgument(ResourceArgument, brushResource)
propertyType | (PropertyType) | The PropertyType argument whose value to set. |
value | (string, number, boolean, KanziObject or userdata) | The value to set. |
Returns the value of an argument.
-- Define the argument property types.
BoolProperty = PropertyType:new("project.BoolProperty")
-- Define the message handler.
local messageHandler = function(arguments)
if arguments:getArgument(BoolProperty) then
-- Define functionality here.
end
end
-- Define the message type from the project without linking the message arguments type.
BoolMessage = MessageType:new("BoolMessage")
-- Set the message handler.
contextNode:addMessageHandler(BoolMessage, messageHandler)
propertyType | (PropertyType) | The PropertyType argument whose value to get. |
(string, number, boolean, KanziObject or userdata) | The value of the argument. |
Returns the source node for a message.
(Node) | The instance of the Node-derived class from where the message was dispatched. |
Sets the handling status for a message.
handled | (boolean) | The new handling status. |
Returns whether the message is handled.
(boolean) | If the message is handled, true, otherwise false. |