Compile-time type checking ADVPL

Asked

Viewed 829 times

2

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

I wonder if anyone knows any way to check compile-time types using ADVPL or if there is some newer version of the language that does this.

I tried searching for runtime type checking using ADVPL but all I find are articles related only to compilers and not to the language itself.

  • To avoid long discussions in the comments; your conversation was moved to the chat

4 answers

4


Gabriel, I don’t know any way to test types at the time of compilation in Advpl, the types are checked in the program’s Runtime same! With the Eclipse-based Totvs Developer Studio you get a better syntactic and semantic analysis! If you are using you can check which one is the one that most heated to you follows the links:

I prefer the 12 he and lighter and syntax hilight and better than the 13, can use the VS code also has the plugin https://marketplace.visualstudio.com/items?itemName=KillerAll.advpl-vscode. It the debug and compilation are working well with the Protheus V12, the 11 is giving some problems.

Test without opening the ERP manually

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

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

Example below using 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 the smartclient run and the initial program U_nomefucao instead of SIGAMDI or SIGAADV. It saves time to open ERP, if your program is background only and does not involve visual components!

To test the Variables types you can use the functions

  • Clearvarsetget
  • Conttype (Returns an array with the type of the variable. Unlike Valtype, returns the original type of the variable)
  • Type (Returns the data type of an expression or variable)
  • Scan (Creates reference between two variables)
  • Valtype (Returns a character that identifies the data type of the given variable through the parameter)
  • Varsetget (Allows you to associate a code block to an Advpl program variable, where the code block will be called when the variable is accessed)
  • Link to the Documentation: http://tdn.totvs.com/pages/viewpage.action?pageId=6063952

Now that you know how to test the variaves there we go to the Cast in Advpl and very free and have convert function I will put only a few and leave the link of the official documentation of TOTVS.

  • Val( < cString > ) Converts a string of characters containing digits to a numerical value.
  • Ctod( < cdata > ) Converts a formatted string to date type
  • cValToChar( < xParametro > ) Converts an information of type character, date, logic or numeric to string, without adding spaces in the information.

So you can see the rest according to your need in the link documentation http://tdn.totvs.com/pages/viewpage.action?pageId=6063599

This other link brings a list with all the functions the SDK documented see according to your need link http://tdn.totvs.com/pages/viewpage.action?pageId=6063359

What to do with mistakes 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 https://github.com/NaldoDj/BlackTDN/blob/master/include/tryexception.ch

Developed by Marinaldo of Black TDN http://www.blacktdn.com.br/

I hope I’ve helped!

2

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

http://tdn.totvs.com/display/framework/SDK+Microsiga+Protheus

Working with it is super simple if you have knowledge in structured programming. On typing, advpl is much more javascript-like than java. It is not strongly typed. What facilitates a lot in the development of business rules ( that is her focus).

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

2

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

valor := 1
valor := "Um"

Would not be reported as a compile-time error.

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

http://tdn.totvs.com/pages/viewpage.action?pageId=22480357

For Development we suggest using the IDE TOTVS Develop Studio

http://tdn.totvs.com/pages/viewpage.action?pageId=107939969

You can use Visual Studio Code with this extension:

search the github killerall/advpl-vscode

  • 1

    If you want to use vscode the link is:https://marketplace.visualstudio.com/items?itemName=KillerAll.advpl-vscode

1

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

For more information, visit the official TL++ documentation link on TDN -- http://tdn.totvs.com/display/tec/Tipagem+Forte

Browser other questions tagged

You are not signed in. Login or sign up in order to post.