Compile-time type checking ADVPL

1

I'm using the ADVPL language at my stage and having many problems with type errors, variable scope, etc. In general, it should be checked at compile time, but I can only see the error at runtime and for this it is necessary to log in to the system, access the module, etc, etc ...

I would like to know if anyone knows any way to do compile-time type checking using ADVPL or if there is a newer version of the language that does this.

I've tried searching for type checking at runtime using ADVPL, but all I find are compiler-only articles and not the language itself.

    
asked by anonymous 30.05.2017 / 13:42

4 answers

4

Gabriel,    I do not know any way to test types at compile time in Advpl, the types are checked in the same program runtime! With Totvs Developer Studio Based on Eclipse you have a better syntactic and semantic analysis! If you are going to use it, you can check which one is closest to you follow the links:

I prefer 12 and it is lighter and syntax hilight and better than the 13, you can use the VS code also has the plugin link . It debug and build is working well with Protheus V12, at 11 this is giving some problems.

Test without having to open ERP manually

To test your program without having to open ERP manually is there such a possibility? Yes it exists you should use the following code snippet in the program:

PREPARE ENVIRONMENT EMPRESA("02") FILIAL("01") MODULO "COM"
RESET ENVIRONMENT

Example below using the code snippet:

User Fuction NomeFucao() Local variável Local outravar Private varival PREPARE ENVIRONMENT EMPRESA("02") FILIAL("01") MODULO "COM" PROCESSAMENTO DO SEU PROGRAMA AQUI ..... ..... .... RESET ENVIRONMENT Return Variável ou Nil

After that, you have to run smartclient and in the initial program U_FunctionName instead of SIGAMDI or SIGAADV. A sim saves time to open ERP, so if your program is background only and does not involve visual components!

To test the Variable types you can use the

  • ClearVarSetGet
  • ContType (Returns an array with the type of the variable.) Unlike ValType, it returns the original type of the variable.
  • Type (Returns the data type of an expression or variable)
  • VarRef (Creates a reference between two variables)
  • ValType (Returns a character that identifies the data type of the variable entered via the parameter)
  • VarSetGet (Allows to associate a block of code with an Advpl program variable, where the code block will be called when the variable is accessed)
  • Documentation link: link

Now that you know how to test the variations, we'll go to the Cast in AdvPL and it's very free and it has the function to convert everything, I'll just put a few and leave the TOTVS official documentation link.

  • Val (< cString >) Converts a string of characters that contain digits to a numeric value.
  • CtoD () Converts a formatted string to the date type
  • cValToChar () Converts a character, date, logical, or numeric type information to string, without adding any spaces in the information.

So you can see the rest according to your need in the documentation link link

This other link brings a list of all the functions the SDK documented to see according to your need link link

What to do with errors and exceptions

You can use the tryexception library

#include "tryexception.ch" 
Static Function TrySample2() 
  Local bError := { |oError| MyError( oError ) } 
  Local oError 
  ..
  TRYEXCEPTION USING bError 
   //Forçando um erro para avalia-lo. 
   __EXCEPTION__->ERROR := "__EXCEPTION__" 
  CATCHEXCEPTION USING oError 
     //"Se ocorreu erro, após o BREAK, venho para cá" 
     MsgInfo( oError:Description , "Peguei o Desvio do BREAK" ) 
  ENDEXCEPTION 
  MsgInfo( "Continuo após o tratamento de erro" ) 
Return( NIL )

She's on GitHub link link

Developed by Marinaldo do Black TDN link

I hope I have helped!

    
08.08.2017 / 16:12
2

With the release of the new version of TOTVS Application Server 64 bits, called "Lobo Guará", it will be possible to program using a new AdvPL code, differentiated by file extension, with strengths in object orientation and variable typing - - TL ++ language.

For more information, see the official TL ++ documentation link on TDN - link

p>     
05.10.2018 / 07:13
1

The ADVPL language has dynamic typing, meaning the type is defined as you assign it. what in case:

valor := 1
valor := "Um"

It would not be reported as a compile-time error.

To help in this matter we use a good practice manual and in it contains convention tips and how to organize your code.

link

For Development we suggest the use of TOTVS Develop Studio IDE

link

You can also use Visual Studio Code with this extension:

search github killerall / advpl-vscode

    
05.06.2017 / 18:56
1

ADVPL is a language that has its origin in Clipper. For you to start on it you can use any Clipper manual as a base, but strongly recommend reading the material available at:

link

Working with it is super simple if you are knowledgeable about structured programming. About typing, advpl is much more like javascript than java. Not being strongly typed. This makes it much easier to develop business rules (which is the focus of it).

If you have something more specific with the source code, open a question with it so we can help.

    
15.06.2017 / 04:28