#COMMAND
#Command
Purpose
#Command allows you to define new commands using sequences of existing DataFlex commands.
Caution
The creation of custom commands is not recommended or supported. Custom commands are also not supported in the Studio via CodeSense or any other Studio tools. We recommend using object-oriented techniques such as creating classes and class methods instead.
Syntax
#Command {new-command} [{symbol-list1 … symbol-list9}]
directive line
:
directive line
#EndCommand
Argument Explanation
-
new-command: Is the name assigned to the new command macro you have created. The identifier that you assign to the new command must not be a DataFlex reserved word.
-
symbol-list: Each command may optionally be followed by up to nine lists of symbols. Each list corresponds to one of up to nine possible arguments that can be passed to the new command. The symbols are used to perform error type checking on the arguments during compilation. Symbol checking is more thoroughly explained in and after the explanation of the #Check compiler directive, which uses the same syntax. Do not type the brackets; they only signify that the command component is optional.
What It Does
When used in a program, your new command will look just like any other command in DataFlex, but it will in fact cause execution of a sequence of other DataFlex commands. The command must be defined before it is first used in the program.
#Command Sign_On
Showln
Showln 'EXAMPLE PROGRAM'
Showln '(c) 1999 DATA ACCESS CORP'
Showln
#EndCommand
This macro defines a new command, Sign_On. Whenever it is used in a program, the four indented command lines above will be executed in its place (it displays the two-line banner in quotation marks, surrounded by a couple of blank lines).
In the next example, suppose that we wish to be able to insert the name of the program (instead of the hard-coded legend EXAMPLE PROGRAM shown above) as an argument to the Sign_On command. The syntax for an argument is an exclamation point with an integer between 1 and 9 after it. The command model will then textually substitute the first argument written after the command into the command model wherever !1 appears in it, the second argument (if any) wherever !2 appears, and so on.
#Command Sign_On R .
Showln
Showln !1
Showln '(C) 1999 DATA ACCESS CORP.'
Showln
#EndCommand
The !1 used above would be replaced by the first argument following the use of Sign_On. A use of this new command macro could be:
Sign_On 'ACCOUNTS PAYABLE PROGRAM'
ACCOUNTS PAYABLE PROGRAM would then be substituted at the !1 position when the command was compiled. Nine arguments can be replaced in this manner (i.e., !1 !2 !3 ... !9). The symbol !0 is the total number of arguments that have been passed to a macro command.
The 'R' symbol in the #Command definition specifies that one argument must be passed to the Sign_On command when it is used. The '.' symbol specifies that no further arguments may follow.
Notes
-
CAUTION: Macros are not routines. A macro used five times in a source program will be expanded each time, so frequent use of a large macro can result in excessive memory consumed by the executable program. Generally, larger macros can be more simply installed and used within less file space if written as procedures or functions.
-
The macro is a powerful tool. Replacements can be made anywhere within the expansion, and a macro can even call other macros.