Macros and Compiled Programs

Macros and Compiled Programs

Welcome to our Knowledge Base

Documentation | Blog | Demos | Support

< All Topics
Print

Macros and Compiled Programs

Macro substitution takes place only when the software is parsing a source (uncompiled) program.

During compilation, the software parses the source code and performs macro substitution based on current macro values. The resulting commands are then compile and stored in compiled form.

When the compiled program is executed, its source code is not parsed again. Therefore, changes to macro values in the interim are not reflected when the compiled program is executed.

For this reason, programs that use macros should not normally be compiled.

Problems that can arise

Consider a program called ExtremeCase that contains a single line of code:

#< CommandLine>

The program ExtremeCase could contain any command, depending on the character string value assigned to the macro < CommandLine>.

If ExtremeCase is not compiled, executing the commands

let = ‘list all Employees’
ExtremeCase
let = ‘form open fTotals’
ExtremeCase

is equivalent to executing

list all Employees
form open fTotals

If ExtremeCase were to be compiled at this point, the command that would be compiled is

form open fTotals

From this point forward, executing the compiled program ExtremeCase would always result in the execution of the FORM OPEN command, regardless of the current value of the macro .

If you choose to compile

IF you choose to compile programs that use macros, keep the following principles in mind:

  • Values for local macros cannot be specified in a call to a compiled macro program

  • After compilation, LET and INPUT assignments to a macro have no effect on the value of that macro in the compiled program.

  • Global macros should be declared and assigned a value before the programs that call them are completed.

  • The software issues a warning when a program that is being compiled contains global macros.

Macros vs Variables

Although macros appear to behave as variables do, they are, in fact, quite different:

  • Variables are defined in the Object Dictionary, with a given data type, length, and so on.

  • Variables are objects in the application database.

  • Variables can be unassigned ($Null).

  • The value of a variable can vary at execution time, even in fully compiled applications.

On the other hand

  • macros are not defined in the Object Dictionary.

  • macros are not objects in the application database.

  • macros always have a value; they cannot be $Null.

  • macro values are substituted for macro calls when commands are parsed. Data, object names, and entire commands can all be used as macro values.

  • macro substitutions are not re-evaluated when a compiled program is executed. Once a program is compiled, changes to the values of macros have not effect on the compiled code.  

Was this article helpful?
0 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.

Leave a Reply

Your email address will not be published. Required fields are marked *

en_CAEnglish