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!
To avoid long discussions in the comments; your conversation was moved to the chat
– Bacco