Usina BRAdvPL Guide
Sign in
← All topics
DIRECTIVEPublished

#command and #translate

#command <regra> => <resultado> · #translate <regra> => <resultado>

Creates syntax-transformation rules applied by the preprocessor.

Pré-processadorTradução sintáticaComandosArquivos .ch
01 · OVERVIEW

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.

02 · SYNTAX

Syntax

#command <regra> => <resultado> · #translate <regra> => <resultado>
03 · PRACTICAL EXAMPLE

Simple teaching command

#command SHOW_ALERT <cMessage> => ;
    MsgStop(<cMessage>, "System warning")

User Function ExCommand()
    SHOW_ALERT "Insufficient balance"
Return
Expected result

The statement is transformed into MsgStop() before compilation.

04 · PRACTICAL EXAMPLE

Localized translation

#translate VERDADEIRO => .T.
#translate FALSO      => .F.

User Function ExTranslate()
    Local lValido := VERDADEIRO

    If lValido == VERDADEIRO
        ConOut("Valor válido")
    EndIf
Return
Expected result

Identifiers are translated into logical values before compilation; weigh readability against nonstandard syntax.

BEST PRACTICES
  • 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.
COMMON PITFALLS
  • 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.

Related content

REFERENCES
  1. TOTVS. #define. TDN. Última alteração em 22 mar. 2019.
  2. TOTVS. Diretivas para o compilador. TDN.
  3. TOTVS. #ifdef. TDN.
  4. TOTVS. #ifndef. TDN.
  5. TOTVS. #include. TDN.
  6. TOTVS. #undef. TDN.
Status
Published
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR