Pessoal,
Uma duvida:
O USO DE AS
LOCAL nNumero AS NUMERIC, aVetor AS ARRAY, lLogico AS LOGICAL, dData AS DATE, hRecord AS HASH, cString AS STRING, bBlock AS CODEBLOCK
O que o harbour faz quando eu defino assim uma variável?

Moderador: Moderadores
JoséQuintas escreveu:Se não me engano, ele só vai dar erro em run-time se o conteúdo for outro.
Isso não ajuda muito, porque em run-time já é tarde demais.
### STRONG TYPED VARIABLES ###
====================================
Harbour and xHarbour allow to declare type of variables using syntax similar
to Visual Object which was adopted also by FlagShip and some other xBase
compatible languages (i.e. FlagShip):
LOCAL var AS STRING
Anyhow so far in both compilers it is only source code decoration and it's
simply ignored during compilation. The syntax is similar but not the same.
In VO:
LOCAL var1, var2 AS LOGICAL
means that var1 and var2 are character variables and are initialized to .F.
at runtime. In Harbour and xHarbour 'AS <type>' has to be repeated after
each variable so in above code only var2 is strongly typed but not var1.
To declare both variables as logical ones it should be changed to:
LOCAL var1 AS STRING, var2 AS STRING
Such syntax is also not compatible with syntax of typed object variables
(see TYPED OBJECT VARIABLES below) where
VAR v1, v2 AS LOGICAL
declares both variables as logical ones.
This can strongly confuse users so in the future adding fully functional
support for strong typed variables probably it will be changed to syntax
compatible with other xBase compatible languages.
Now please remember that neither Harbour nor xHarbour make type validation
during compilation and at runtime and typed variables are not implicitly
initialized to empty value of given type.
### TYPED OBJECT VARIABLES ###
====================================
Harbour supports strong typed object variables, f.e.:
CREATE CLASS MyClass
VAR var1 AS INTVAR
VAR var2 AS NUMERIC
VAR var3 AS DATE
VAR var3 AS CHARACTER
ENDCLASS
And validates assigned values at runtime just like in Class(y).
Variables declared as numeric, logical, date and timestamp without
explicit initialization value (INIT clause) are initialized to empty
value of given type. This functionality can be disabled defining
HB_CLS_NOAUTOINIT macro before including hbclass.ch.
xHarbour can compile above code but AS <type> is only used to
initialize numeric and logical values to 0 and .f.
Usuários vendo este fórum: Nenhum usuário registrado online e 9 visitantes