Olá Toledo,
O que você me diz destes exemplos do harbour:
Estes exemplos estão na pasta \trunk\harbour\tests
Note que a variável static z := "First" (no exemplo abaixo) está sendo inicializada no inicio, fora de qualquer function, e sendo usada na function NumStat()
me corrija se estiver errado.
//
// $Id: statics.prg 1519 1999-10-04 18:46:41Z vszel $
//
// Testing Harbour statics variables management
static z := "First"
function Main()
LOCAL i, cb
static a := "Hello", b := { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
QOut( a )
QOut( b[ 2 ] )
Two()
QOut( "Ok!" )
FOR i:=1 TO 10
NumStat()
NEXT
cb :=DetachVar( 10 )
FOR i:=1 To 10
QOut( EVAL( cb, b[ i ] ) )
NEXT
return nil
function Two()
static a := "Test"
QOut( a )
return nil
FUNCTION THREE( p )
QOut( p )
RETURN p
PROCEDURE NumStat(a)
STATIC n:=1
LOCAL cb
//STATIC m:=n //uncomment it to see an error
//STATIC m:=Time() //uncomment it to see an error
cb :={|x| z +STR(x)}
QOut( ++n )
QOut( EVAL( cb,n ) )
RETURN
FUNCTION DetachVar( xLocal )
STATIC xStatic:=100
RETURN( {|x| ++xStatic, x+xStatic+xLocal} )
static uOne, uTwo
function Main()
QOut( "Statics overlapped!" )
QOut( "===================" )
QOut( "" )
QOut( "INSIDE statics1.prg" )
QOut( " static uOne, uTwo" )
QOut( "" )
QOut( " uOne, uTwo =>", uOne, ",", uTwo )
uOne := 1
uTwo := 2
QOut( " uOne := 1" )
QOut( " uOne := 2" )
QOut( " uOne, uTwo =>", uOne, ",", uTwo )
QOut( "" )
Test()
QOut( "INSIDE statics1.prg" )
QOut( " uOne, uTwo =>", uOne, ",", uTwo )
QOut( "" )
return nil
static uA, uB
function Test()
QOut( "INSIDE statics2.prg" )
QOut( " static uA, uB" )
QOut( "" )
QOut( " ValType( uA ), ValType( uB ) =>", ValType( uA ), ",", ValType( uB ) )
QOut( " uA, uB =>", uA, ",", uB )
uA := "a"
uB := "b"
QOut( ' uA := "a"' )
QOut( ' uB := "b"' )
QOut( " uA, uB =>", uA, ",", uB )
QOut( "" )
return nil