Command: Auto Declare
Shortcut: Shift + F2
Function: The command opens the Auto Declare dialog which helps to declare a variable.
Call: menu
Requirement: An object or a device of the project is open in the editor.
With the auto-declaration function, the Auto Declare dialog is also displayed when the cursor is positioned in the implementation part of a POU in a line which contains the name of an undeclared variable. The requirement is that you first have to select the Declare unknown variables automatically (AutoDeclare) option in the menu, in the SmartCoding category.
With the smart tag function, the Auto Declare command is also displayed when you place the cursor over an undeclared variable in the implementation part of the ST editor and then click .
Dialog: Auto Declare
Scope | Scope of the variable which is not declared yet Example: |
Name | Variable name which is not declared yet Example: |
Type | Example:
|
Object | Object where the new variable is declared By default, the object which you are editing right now. Example:
If no objects are available for the selected Scope, then the <create object> entry is displayed. When you select the <create object> entry, the Add Object dialog opens to generate a suitable object. |
Initialization | Example: If you do not specify an initialization value, then the variable is initialized automatically.
This method is helpful for the initialization of structured variables. |
Address | Memory address of the application for the variable which is not declared yet Example: Note: . Possible only for the following scopes:
|
Flags | . Attribute keywords
The selected attribute keyword is added to the variable declaration. |
Comment | Example: In the tabular declaration editor, the specified comment is displayed in the Comment column, while in the textual declaration editor it is displayed above the variable declaration. |
Apply changes using refactoring |
. The option appears for the following scopes:
|
OK | The variable is declared and is displayed in the declaration. Example: VAR RETAIN // New input In1 xIn1 AT %IX1.0: BOOL := FALSE; END_VAR |
Dialog: Array
Ranks and Base Type Specification | Definition of the field sizes (Dimension) by specifying the upper and lower limits and the Base Type of the array You can specify the base type directly, or click the |
Result | Display of the defined array |
Important
CODESYS reinitializes variables only if you have changed the initialization values of the variables.
Dialog: Initialization value
List of the variables by name (Expression), Initialization Value and Data Type Changed initialization values are displayed in bold fonts. | |
Input field below the list | Input of an initialization value for the selected variable(s) |
Apply Value to Selected Lines | Change of the initialization value of the selected line(s) according to the value of the input field |
Reset Selected Lines to Default Values | Resets to the default initialization values |
OK | CODESYS applies the initialization values in the Auto Declare dialog. |
In the case that the variable to be initialized by means of this dialog is a function block instance with an extended FB_Init method, an additional table is displayed above the Initialization Value table. The additional FB_Init parameters are listed in this table. The meaning and handling essentially correspond to the lower table with the following differences:
All variables have to be assigned with initialization values. Otherwise OK remains disabled.
For complex data types (structures, arrays), no components contained within are displayed (type cannot be expanded). In this case, the complex type has to be initialized with a corresponding variable.
For FB_Init parameters configured this way, a corresponding symbol is displayed after the initialization value in the Auto Declare dialog.
For more information, see: Method: FB_Init
, FB_Reinit
, FB_Exit
and AT Declaration