Página 1 de 1
A utilização da função SCROLL
Enviado: 11 Mar 2013 11:32
por Jeferson
Estou colocando esse assunto no forum para saber se alguém pode me ajudar a achar o erro que esta dando:
Na execução do programa a mensagem de erro é que a variável "aPos" não existe.
Eu não estou conseguindo visualizar para corrigir.
Preciso de ajuda.
segue abaixo a parte onde está dando o erro:
A variável é declarada como Estatica e depois eu utilizo a função SCROLL() para chamá-la, e o erro é que ela não existe.
Código: Selecionar todos
STATIC aPos := { { 05,28,37 } ,;
{ 07,28,37 } ,;
{ 08,28,37 } ,;
{ 09,28,37 } ,;
{ 10,28,37 } ,;
{ 12,28,37 } ,;
{ 13,28,37 } ,;
{ 15,28,37 } ,;
{ 16,28,37 } ,;
{ 18,28,37 } ,;
{ 19,28,37 } }
FUNCTION MontaTela()
// Apaga area e desenha moldura
SCROLL(aPos[1][1]-2, aPos[1][2]-1, MAXROW()-3, MAXCOL()-2, 0)
@ aPos[1][1]-2, aPos[1][2]-1 TO MAXROW()-3, MAXCOL()-2
// Escreve Mensagens
@ aPos[EMPRESA][1], aPos[EMPRESA][2] SAY "Empresa"
@ aPos[ENDERECO][1], aPos[ENDERECO][2] SAY "Endereco"
@ aPos[CIDADE][1], aPos[CIDADE][2] SAY "Cidade"
@ aPos[ESTADO][1], aPos[ESTADO][2] SAY "Estado"
@ aPos[CEP][1], aPos[CEP][2] SAY "Cep"
@ aPos[CONTATO][1], aPos[CONTATO][2] SAY "Contato"
@ aPos[DEPTO][1], aPos[DEPTO][2] SAY "Depto"
@ aPos[TELEFONE][1], aPos[TELEFONE][2] SAY "Telefone"
@ aPos[EMAIL][1], aPos[EMAIL][2] SAY "E-mail"
@ aPos[RAMOATIV][1], aPos[RAMOATIV][2] SAY "Ramo"
@ aPos[CADASTRO][1], aPos[CADASTRO][2] SAY "Data"
// Escreve mensagem de rodape e ...
// retorna salvando a tela
StatMens("Digite dados. ESC p/ sair ")
RETURN SAVESCREEN(0,0,MAXROW(), MAXCOL())
A utilização da função SCROLL
Enviado: 11 Mar 2013 12:26
por Jairo Maia
Olá Jeferson,
Eu acho que é porque ela está sendo declarada como STATIC por isso não é vista pela função SCROLL. Tente declarar como PRIVATE na função que você chama a função MontaTela()
Quando você declara uma variável ou função como STATIC, ela somente será vista no mesmo modulo. Como a função SCROLL não está neste módulo, ela não é vista.
A utilização da função SCROLL
Enviado: 11 Mar 2013 14:44
por Jeferson
Beleza, funcionou por que eu sair daquela mensagem de erro.
Mais agora ele imprimi as primeiras linhas e quando chega no telefone ele dá erro de argumento:acesso array, e suprime as linhas restantes. Por quê?
Jeferson.
A utilização da função SCROLL
Enviado: 11 Mar 2013 15:10
por Jairo Maia
Jeferson, verifique se os valores declarados das variáveis de identificação estão nesta sequência:
Código: Selecionar todos
EMPRESA := 01
ENDERECO := 02
CIDADE := 03
ESTADO := 04
CEP := 05
CONTATO := 06
DEPTO := 07
TELEFONE := 08
EMAIL := 09
RAMOATIV := 10
CADASTRO := 11
Se elas foram declaradas em arquivo .CH, basta não usar o indicador de inicialização, a saber
:=
A utilização da função SCROLL
Enviado: 11 Mar 2013 16:34
por alxsts
Olá!
Jefferson, você construiu seu código da maneira mais correta. Declarou uma variável estática antes da primeira função do arquivo PRG. Assim, ela se torna visível a todas as funções e procedures do arquivo PRG, desde que você compile esse PRG com o parâmetro /N. Foi isso que faltou.
Esse é o melhor método, visto que as variáveis estáticas, assim como as locais, são mais "rápidas" que as private e public, alem de terem um controle de escopo mais bem definido.
A utilização da função SCROLL
Enviado: 12 Mar 2013 08:19
por Jeferson
Obrigadão pela ajuda.
É bom saber que temos pessoas que podemos contar para podermos sanar nossas dúvidas.
As duas informações foram precisas para que os programinhas pudessem rodar de maneira satisfatorio e que pudesse atender as necessidades basicas.
Valeu mesmo.
Jeferson.
A utilização da função SCROLL
Enviado: 12 Mar 2013 11:35
por Jairo Maia
Jeferson, que legal que está resolvendo suas dúvidas. O objetivo do fórum é este mesmo: ajudar e ser ajudado sempre que possível, bem como aprender novas coisas.
Alexandre, eu não tinha a menor ideia que o parâmetro /N tinha também essa característica. Sempre achei que a função dele fosse apenas não considerar implicitamente o nome do módulo como procedure. Valeu a dica.
A utilização da função SCROLL
Enviado: 12 Mar 2013 12:41
por alxsts
Olá!
É o velho Clipper, mostrando que ainda não sabemos tudo a respeito dele. Veja a seção descrição abaixo. Extraído do NG do Clipper 5.2.
Código: Selecionar todos
STATIC
Declare and initialize static variables and arrays
------------------------------------------------------------------------------
Syntax
STATIC <identifier> [[:= <initializer>], ... ]
Arguments
<identifier> is the name of the variable or array to declare static.
If the <identifier> is followed by square brackets ([ ]), it is created
as an array. If the <identifier> is an array, the syntax for specifying
the number of elements for each dimension can be array[<nElements>,
<nElements2>,...] or array[<nElements>] [<nElements2>]... The maximum
number of elements per dimension is 4096. The maximum number of
dimensions is limited only by available memory.
<initializer> is the optional assignment of a value to a new static
variable. An <initializer> for a static variable consists of the inline
assignment operator (:=) followed by a compile-time constant expression
consisting entirely of constants and operators or a literal array. If
no explicit <initializer> is specified, the variable is given an initial
value of NIL. In the case of an array, each element is NIL. Array
identifiers cannot be given values with an <initializer>.
Note: The macro operator (&) cannot be used in a STATIC declaration
statement.
Description
The STATIC statement declares variables and arrays that have a lifetime
of the entire program but are only visible within the entity that
creates them. Static variables are visible only within a procedure or
user-defined function if declared after a PROCEDURE or FUNCTION
statement. Static variables are visible to all procedures and functions
in a program file (.prg) (i.e., have filewide scope) if they are
declared before the first procedure or user-defined function definition
in the file. Use the /N compiler option to compile a program with
filewide variable scoping.
All static variables in a program are created when the program is first
invoked, and all values specified in a static <initializer> are assigned
to the variable before the beginning of program execution.
Declarations of static variables within a procedure or user-defined
function must occur before any executable statement including PRIVATE,
PUBLIC, and PARAMETERS. If a variable of the same name is declared
FIELD, LOCAL, or MEMVAR within the body of a procedure or user-defined
function, a compiler error occurs and no object file (.OBJ) is
generated.
The maximum number of static variables in a program is limited only by
available memory.
Notes
. Inspecting static variables within the Debugger: To access
static variable names within The CA-Clipper Debugger, you must
compile program files (.prg) using the /B option so that static
variable information is included in the object file (.OBJ).
. Macro expressions: You may not refer to static variables
within macro expressions or variables. If a static variable is
referred to within a macro expression or variable, a private or
public variable of the same name will be accessed instead. If no
such variable exists, a runtime error will be generated.
. Memory files: Static variables cannot be SAVED to or RESTOREd
from memory files (.mem).
. Type of a static local variable: Since TYPE() uses the macro
operator (&) to evaluate its argument, you cannot use TYPE() to
determine the type of a local or static variable or an expression
containing a local or static variable reference. The VALTYPE()
function provides this facility by evaluating the function argument
and returning the data type of its return value.
Examples
. This example declares static variables both with and without
initializers:
STATIC aArray1[20, 10], aArray2[20][10]
STATIC cVar, cVar2
STATIC cString := "my string", var
STATIC aArray := {1, 2, 3}
. This example manipulates a static variable within a user-defined
function. In this example, a count variable increments itself each
time the function is called:
FUNCTION MyCounter( nNewValue )
STATIC nCounter := 0 // Initial value assigned once
IF nNewValue != NIL
nCounter:= nNewValue // New value for nCounter
ELSE
nCounter++ // Increment nCounter
ENDIF
RETURN nCounter
. This example demonstrates a static variable declaration that
has filewide scope. In this code fragment, aArray is visible to both
procedures that follow the declaration:
STATIC aArray := {1, 2, 3, 4}
FUNCTION One
? aArray[1] // Result: 1
RETURN NIL
FUNCTION Two
? aArray[3] // Result: 3
RETURN NIL
Naturalmente, isso vale para Harbour e xHarbour.