Alternativa a variable PUBLIC

Post Reply
User avatar
jvtecheto
Posts: 357
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Alternativa a variable PUBLIC

Post 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.
Fwh 19.06 32 bits + Harbour 3.2dev(r2011030937)+ Borland 7.4 + FivEdit
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Alternativa a variable PUBLIC

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
jvtecheto
Posts: 357
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Re: Alternativa a variable PUBLIC

Post by jvtecheto »

Thanks Mr. Rao.

Works fine.

Regards.

Jose
Fwh 19.06 32 bits + Harbour 3.2dev(r2011030937)+ Borland 7.4 + FivEdit
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Alternativa a variable PUBLIC

Post 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
User avatar
jvtecheto
Posts: 357
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Re: Alternativa a variable PUBLIC

Post by jvtecheto »

Hi

Other alternative.

Thanks for your suggestion Rick.

Regards

Jose

Enviado desde mi ONE A2003 mediante Tapatalk
Fwh 19.06 32 bits + Harbour 3.2dev(r2011030937)+ Borland 7.4 + FivEdit
Post Reply