Código: Selecionar todos
Memvar cVar
Procedure Main()
Public cVar:= 'Hello World'
Teste()
Return
Código: Selecionar todos
Function Teste()
? cVar
Return(Nil)
Moderador: Moderadores

Código: Selecionar todos
Memvar cVar
Procedure Main()
Public cVar:= 'Hello World'
Teste()
Return
Código: Selecionar todos
Function Teste()
? cVar
Return(Nil)

No segundo fonte, falta declarar a variável.test4.prg:2: warning W0001 Ambiguous reference 'CVAR'
Código: Selecionar todos
// fonte1.prg
Memvar cVar
Procedure Main()
Public cVar:= 'Hello World'
Teste()
Return
//fonte2.prg
MEMVAR cVar // <<<<====
Function Teste()
? cVar
Return Nil // <=== Porque poluir fonte ? RETURN não é função
Código: Selecionar todos
// fonte1.prg
LOCAL cVar := "Hello World"
Teste( cVar )
RETURN
// fonte 2.prg
FUNCTION Test( cTexto )
? cTexto
RETURN Nil

Compile com -N, além dos demais parâmetros de compilação que já utiliza.Softwhouse escreveu:Como resolver o erro...



Fonte: Norton Guides - Clipper 5.3MEMVAR
Declare private and public variable names
------------------------------------------------------------------------------
Syntax
MEMVAR <idMemvar list>
Arguments
<idMemvar list> is a list of public and private variable names to declare to the compiler.
Description
MEMVAR is a declaration statement that causes the compiler to resolve references to variables specified without an explicit alias by implicitly assuming the memory variable alias (MEMVAR->). Only explicit, unaliased references to the specified variables are affected.
MEMVAR, like all declaration statements, has no effect on references made within macro expressions or variables.
The MEMVAR statement neither creates the variables nor verifies their existence. Its primary effect is to ensure correct references to variables whose existence is known to be guaranteed at runtime. At runtime, the specified variables must be created using the PRIVATE, PARAMETERS or PUBLIC statements. This can occur in the procedure containing the MEMVAR declaration or in a higher -level procedure.
Attempting to access the variables before they are created will cause an error.
The scope of the MEMVAR declaration is the procedure or function in which it occurs, or the entire source file if it precedes any PROCEDURE or FUNCTION statements and the /N compiler option is used. The /N option suppresses automatic definition of a procedure with the same name as the program (.prg) file.
Like other declaration statements, MEMVAR must precede any executable statements, including PARAMETERS, PUBLIC, and PRIVATE statements in a procedure or function definition, or the program (.prg) file if the declaration has filewide scope.
MEMVAR can be used in conjunction with the /W compiler option--which generates warning messages for ambiguous variable references--to perform compile--time checking for undeclared variables.
For more information on variable declarations and scoping, refer to the Variables section in the "Basic Concepts" chapter of the Programming and Utilities Guide.
Examples
. This example demonstrates the relationship between a private
and field variable with the same name. The private variable is
declared with the MEMVAR statement:
FUNCTION Example
MEMVAR amount, address
PRIVATE amount := 100
USE Customer NEW
//
? amount // Refers to amount private variable
? Customer->Amount // Refers to Amount field variable
//
RETURN NIL

Uso de outra forma, principalmente por causa de multithread, mas pra LIB GUI acaba sendo interessante.Softwhouse escreveu:O motivo das varáveis public é que são informadas no prg principal o Path dos arquivos, nome da empresa, arays... para serem utilizados nos outros prgs.
Código: Selecionar todos
#define VAR_IMPRESSORA 2
pub_var[ VAR_IMPRESSORA ]
Código: Selecionar todos
FUNCTION AppVar( x )
STATIC aList[ 100 ]
RETURN aList
...
AppVar()[ VAR_IMPRESSORA ]
Código: Selecionar todos
FUNCTION AppImpressora( xValue )
STATIC AppImpressora := ""
IF PCount() != 0
AppImpressora := xValue
ENDIF
RETURN xValue
...
AppImpressora( "EPSON" )
? AppImpressora()
Código: Selecionar todos
cImpressora := AllTrim( dbfsetup->Impressora )