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!