FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveLinux / FiveDroid (Android) Definir una variable en otro procedimiento o funci贸n
Posts: 170
Joined: Sat Aug 07, 2010 11:36 PM
Definir una variable en otro procedimiento o funci贸n
Posted: Thu Jan 08, 2015 04:00 PM

Trabajo con linux harbour y five linux y mi consulta es como puedo definir una variable en otro procedimiento.
Se puede hacer?

Adjunto el c贸digo que entra en un loop porque no existe en el procedimiento Main la variable mivariable.

function Main()
LOCAL oError := ferrorsys()

?mivarible

Return .T.

include "error.ch"

define NTRIM(n)( LTrim(Str(n)) )

Proc ferrorsys(_swE)
Return ( ErrorBlock( {|e| DefError(e,_swE)} ) )

static func DefError(e,l)
Loca i, cMenssageInf, cDefVariable

cMessageInf := ErrorMessage(e)
cMessage := cMessageInf


if 'Error BASE/1003'$cMessageInf

cDefVariable:=substr(cMessageInf,at(':',cMessageInf)+2)

?cDefVariable
store 'Hola' to &cDefVariable
?&cDefVariable
Return (.T.)
endif

return (.f.)

static func ErrorMessage(e)
loca cMessage

// start error message
cMessage := if( e:severity > ES_WARNING, "Error ", "Warning " )

// add subsystem name if available
if ValType(e:subsystem) == "C"
    cMessage += e:subsystem()
else; cMessage += "???"; end

    // add subsystem's error code if available
    if ValType(e:subCode) == "N"
        cMessage += ("/" + NTRIM(e:subCode))
    else; cMessage += "/???"; end

        // add error description if available
        if ValType(e:description) == "C"
            cMessage += ("  " + e:description)
        end

        // add either filename or operation
        if !Empty(e:filename)
            cMessage += (": " + e:filename)
        elseif !Empty(e:operation)
            cMessage += (": " + e:operation)
        end

return (cMessage)

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Definir una variable en otro procedimiento o funci贸n
Posted: Thu Jan 08, 2015 05:38 PM

Jorge,

La 煤nica soluci贸n que se me ocurre es usar una variable p煤blica que haya sido creada previamente en otro procedimiento, pero el usar variables p煤blicas es una pr谩ctica muy poco recomendable.

De hecho uno de los grandes avances de Clipper 5 fu茅 el proporcionar variables locales y static para evitar el uso de variables public.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 170
Joined: Sat Aug 07, 2010 11:36 PM
Re: Definir una variable en otro procedimiento o funci贸n
Posted: Wed Jan 14, 2015 04:39 PM
Antonio Linares wrote:Jorge,

La 煤nica soluci贸n que se me ocurre es usar una variable p煤blica que haya sido creada previamente en otro procedimiento, pero el usar variables p煤blicas es una pr谩ctica muy poco recomendable.

De hecho uno de los grandes avances de Clipper 5 fu茅 el proporcionar variables locales y static para evitar el uso de variables public.


Antonio, logre solucionarlo agregando a mi errorsys.prg:

#IfDef __SQL__
if 'Error BASE/1003'$cMessageInf
cDefVariable:=substr(cMessageInf,at(':',cMessageInf)+2)
if (vValorVariable:=fField_SQL(cDefVariable))!=NIL
__qqPub( cDefVariable )
store vValorVariable to &cDefVariable.
Return (.T.)
endif
endif
#Endif
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Definir una variable en otro procedimiento o funci贸n
Posted: Wed Jan 14, 2015 04:46 PM

Jorge,

Es una soluci贸n nada aconsejable, pero si te sirve...

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion