#command and #translate
#command <regra> => <resultado> · #translate <regra> => <resultado>Creates syntax-transformation rules applied by the preprocessor.
Overview
#command and #translate define text patterns converted into AdvPL syntax. #command targets commands from the beginning of a statement, while #translate allows substitutions in other positions. They are advanced features commonly found in .ch files and xBase-style command implementations.
Syntax
#command <regra> => <resultado> · #translate <regra> => <resultado>Simple teaching command
#command SHOW_ALERT <cMessage> => ;
MsgStop(<cMessage>, "System warning")
User Function ExCommand()
SHOW_ALERT "Insufficient balance"
ReturnThe statement is transformed into MsgStop() before compilation.
Localized translation
#translate VERDADEIRO => .T.
#translate FALSO => .F.
User Function ExTranslate()
Local lValido := VERDADEIRO
If lValido == VERDADEIRO
ConOut("Valor válido")
EndIf
ReturnIdentifiers are translated into logical values before compilation; weigh readability against nonstandard syntax.
- Keep shared rules in a documented .ch file.
- Avoid names that collide with existing commands, functions, or definitions.
- AAdd() is an AdvPL library function; it is not created by #command.
- A private language inside AdvPL makes searching, debugging, and maintenance harder.
- A broad #translate rule may affect unexpected text.
- Validate markers, optional elements, repetitions, and precedence.
