6.6   Variable Window

There are two kinds of variables in HALCON, corresponding to the two parameter types of HALCON: iconic objects (images, regions, and XLDs) and control data (numbers, strings, handles). The corresponding variables are called iconic and control variables. These variables may possess a value or may be undefined. An undefined variable is created, for example, when loading a program or after inserting an operator with a new variable that is not executed immediately into a program. You may access these undefined variables only by writing to them. If you try to read such a variable, a runtime error occurs. If a variable obtains a value, the variable type is specified more precisely. A control variable that contains, for example, an integer is of type integer. This type might change to real or a tuple of integer after specifying new values for this variable. But it always remains a control variable. Similarly, this is the case for iconic variables, which may contain regions, images, or XLDs. You may assign new values to an iconic variable as often as you want to, but you cannot change its type so that it becomes a control variable.

Figure 6.62: Variable window with instantiated iconic and control variables.

New variables are created in the operator dialog area during specification of operator or procedure call parameters. Here, every sequence of characters without single quotation marks is interpreted as a variable name. If this name did not exist before, the variable is created in the operator dialog area by pressing OK or Enter. The variable type is specified through the type of the parameter where it was used for the first time: Variables that correspond to an iconic object parameter create an iconic variable; variables for a control parameter create a control variable. Every time an operator or procedure call is executed, the results are stored in variables connected to its output parameters. This is achieved by first deleting the contents of the variable and then assigning the new value to it.

The variable window is similar to a watch window used in window-oriented debuggers. Inside this window you are able to keep track of variable values. Corresponding to the two variable types, there are two areas in the variable window. One for iconic data (above or left) and the other for control data (below or right).

All computed variables are displayed showing their iconic or control values (unless the automatic update has been switched off, see section “Runtime Settings ▹ Runtime Settings” on page 179). In case of a tuple result which is too long, the tuple presentation is shortened, indicated by three dots. In this case the full content of a variable can be displayed in an inspection window by double-clicking the value list. See also the following sections.

Breakpoints on Variables

In addition to line-based breakpoints (see section “Program Window” on page 304), breakpoints can also be set on variables. Simply right-click on a variable name and select Set/Clear Breakpoint on Variable. Variables with breakpoints are marked with next to their name.

Once a breakpoint has been set on a variable, the program execution stops whenever its value changes. A change of value is detected in the same way the HDevelop operation != works (see section “Comparison Operations” on page 851):

Using clear_obj does not trigger a variable breakpoint. Use dev_clear_obj instead.

When a breakpoint on a variable triggers, the program execution stops and HDevelop highlights the corresponding variable in the variable window. If the variable is not currently displayed in the selected tab of the variable window, HDevelop switches to the tab Auto (see below).

Information about the event is displayed in the status bar, e.g., HDevelop displays both the old and the new value of a tuple.

Switching Between Horizontal and Vertical Layout

You can toggle the orientation of the two parts of the variable window. To do this, double-click the dividing line between both parts. You can also drag that line to resize the parts.

Managing Variables

In large programs the variable window can become quite cluttered, which makes watching selected variables difficult. Therefore, you can customize the selection of displayed variables. At the bottom of the variable window, the following tabs are available:

All
All variables used by the current procedure are displayed at once. Global variables (see section “Scope of Variables (local or global)”) are marked with .

Auto
The variables of the current and the previous operator call are displayed. This is useful when single-stepping through the program, because only the variables relevant to the current context are displayed.

User
A user-defined selection of variables is displayed. Variables may be added and removed using the context menu of the variable window (see below). If the tab User is active, variables may be added from a list in the context menu. In the other tabs variables are added by selecting them first and clicking Add to User Tab in the context menu.

It is also possible to select a variable name in the program window and drag it to the variable window. The corresponding variable will then be added to the watched variables, and the tab User will be activated.

Global
All global variables (see section “Scope of Variables (local or global)”) of the current program are displayed. This includes global variables in external procedures, even if they are not used in the current program.

The context menu of the global variables includes an additional entry Declared in. It lists the names and line numbers of the procedures that declare (and thus use) the corresponding global variable. Click on an entry to jump to the corresponding location in the program window.