Project members: Macro

With macros you can define code fragments to use wherever the macro name appears within your project implementation. This is a kind of convenient replacement. Typically macros are used as configuration parameters for components within your application. Macro members are represented in Composer by following bricks:

Macros can be defined within a profile member only. Moreover, only the currently active profile determines the currently available macros. With multiple profiles and the enclosed macros you can manage several device/product variant configurations within one and the same project.

Add new macro

First switch to the Composer page for the respective profile member you want to add the new macro.

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

Look in the folder for the template named Macro.

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

Drop the template within the Composer.

Adding a new macro member.

Name the macro

First ensure, that the macro member is selected.

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

Enter the new macro name in the Inspector window.

The assigned name identifies uniquely the macro within your project. For example, you can involve the macro name in expressions to conditionally build your application.

Edit the content of the macro

Every macro contains a text or code fragment to incorporate by Chora compiler wherever the corresponding macro name occurs in your project. Do following to specify and modify this content:

First ensure, that the macro member is selected.

In the middle area of the Inspector window locate and adapt the attribute Content.

Duplicate an existing macro

You can create any number of copies of an already existing macro member.

First ensure, that the macro member is selected.

Press the keys CtrlC and CtrlV in succession ...

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

Finally rename the just duplicated macro member.

Macro replacement

You can use the macro as operand within Chora expressions and as initialization value in the most member attributes, as long as the content of the macro is syntactically permitted in the particular context. In order to be distinguished as such, the macro name must be prefixed by a $ (dollar) sign wherever the macro should be evaluated in your project.

Let's assume, your currently selected profile contains a macro named Copyright defined with the content 2016 Company Name. To evaluate this macro within your project use simply the identifier $Copyright. You can, for example, use the macro within a string literal:

var string text = "Copyright $Copyright"; // text = "Copyright 2016 Company Name"

Macros and conditional compilation

Macros can be evaluated in expressions and conditions allowing particular components or code fragments being compiled conditionally depending on the content of the macro.

Delete a macro

First ensure, that the macro member is selected.

Press the key DEL or select the menu item EDITDelete.

Attributes of a macro

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

Attribute name

Short description

Brick

Determines the position and the size of a macro member brick within the Composer window.

Content

Determines the content of a macro member.

Description

Contains the description for the macro member.

Chora syntax of a macro

This section describes the Chora syntax of how macros are stored inside Embedded Wizard project files. The knowledge about the syntax can be helpful when you plan to process the project contents by third party tools. In particular, the general purpose Export and Import functionality introduced in version 14 requires a good understanding of how project members are represented in Chora syntax to correctly interpret the exported members and synthesize the Chora code for members to import. Please note, Embedded Wizard project files (and thus Chora code) are encoded as text in UTF-8 format.

In Chora syntax, macro definition is always introduced with the keyword macro, followed by the name of the macro and its associated content. The name and the content are separated by an assignment operator = and the complete macro definition terminates with ; semicolon sign. Wherever necessary, the tokens are separated by whitespace signs. The content corresponds to the value of the attribute Content.

The definition of a macro can be initiated by a comment block providing optional description for the macro. The content of this comment corresponds to the value of the macros's attribute Description. Furthermore the directive $rect can be specified providing value for the corresponding attribute Brick. The following example demonstrates the described syntax:

// This is a macro. Wherever the macro is used in the project, its associated \ // content (here 'true') is used. // // $rect determines the position of the brick inside Composer window. $rect <10,10,210,50> macro EnableTest = true;

Each Chora file (or text exchanged with an external Export and/or Import tool) can be (or even should be) prefixed with $version directive. This directive determines the version number of the included Chora code. For details concerning the syntax of the version please see the chapter $version macro. Furthermore, the code can include a $scope directive followed by a path to a project member acting as the original owner of the corresponding code. That means the members described by the Chora code existed inside the member specified in $scope. In case of a macro, $scope would specify the name of the profile the macro belongs to.