Page 1 of 1

Alternativa a variable PUBLIC

Posted: Sat Jun 08, 2019 2:00 pm
by jvtecheto
Hola :

En una aplicacion debo almacenar el directorio raiz de la aplicacion , ya que luego
tengo las bases de datos de cada empresa en "\RAIZ\EMP01".

etc. al final para no usar una cadena fija y que el usuario pueda instalar la aplicacion donde quiera.
He definido una variable publica en el PROCEDURE INIT de la aplicacion.

Code: Select all

INIT PROCEDURE ObrasInit()
 PUBLIC cDirectApp := "\" + CurDir()
// ...... Mas codigo
RETURN 
Es porque tengo que utilizar la variable en otros modulos que no son el principal.
para otras variables las declaraba STATIC en el modulo principal
y para exportarlas definia una funcion

Code: Select all

STATIC oWnd
STATIC GetoWnd() ; RETURN oWnd
 
luego en otro .PRG en el modulo a utilizarlas
definia una variable local

Code: Select all

LOCAL oWnd := GetoWnd()
 
y esto me funciona con arrays y objetos pero si intento con esta variable de cadena no funciona.

¿Existe alguna alternativa mejor a definir una varialbe PUBLIC ?

Solo tengo una .

Saludos.

Jose.

Re: Alternativa a variable PUBLIC

Posted: Sat Jun 08, 2019 3:31 pm
by nageswaragunupudi
1) This works with string variables also.
2) It is not necessary to store this information as public.
In any module, simply call

Code: Select all

cFilePath( ExeName() )
 
to know the exe file path.

Re: Alternativa a variable PUBLIC

Posted: Sat Jun 08, 2019 5:06 pm
by jvtecheto
Thanks Mr. Rao.

Works fine.

Regards.

Jose

Re: Alternativa a variable PUBLIC

Posted: Sat Jun 08, 2019 5:25 pm
by Rick Lipkin
brakaman

You can easily use the xBase Set Default .. consider this code .. adding to Rao's suggestion

Code: Select all

cFilePath ( ExeName ( ) )
SET DEFAULT to ( cFilePath )
 
Here is how I get the default path or location where the .Exe resides ( rao's suggestion is more elegant )

Code: Select all

// where .exe started from is default directory //

cFILE  := GetModuleFileName( GetInstance() )
nSTART := RAT( "\", cFILE )
cDEFA  := SUBSTR(cFILE,1,nSTART-1)

SET DEFAULT to ( cDEFA )    // note this command .. 
Then from any module in your program you can access this xBase command Set(7) which retrieves the Set Default value ...

Code: Select all

cFileName := set(7)
 
Rick Lipkin

Re: Alternativa a variable PUBLIC

Posted: Sun Jun 09, 2019 8:44 am
by jvtecheto
Hi

Other alternative.

Thanks for your suggestion Rick.

Regards

Jose

Enviado desde mi ONE A2003 mediante Tapatalk