Alternativa a variable PUBLIC

Alternativa a variable PUBLIC

Postby jvtecheto » Sat Jun 08, 2019 2:00 pm

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  Expand view

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  Expand view

STATIC oWnd
STATIC GetoWnd() ; RETURN oWnd
 


luego en otro .PRG en el modulo a utilizarlas
definia una variable local
Code: Select all  Expand view

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(r2104281802) + Borland 7.4 + FivEdit
User avatar
jvtecheto
 
Posts: 584
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Re: Alternativa a variable PUBLIC

Postby nageswaragunupudi » Sat Jun 08, 2019 3:31 pm

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  Expand view

cFilePath( ExeName() )
 

to know the exe file path.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10465
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Alternativa a variable PUBLIC

Postby jvtecheto » Sat Jun 08, 2019 5:06 pm

Thanks Mr. Rao.

Works fine.

Regards.

Jose
Fwh 19.06 32 bits + Harbour 3.2dev(r2104281802) + Borland 7.4 + FivEdit
User avatar
jvtecheto
 
Posts: 584
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Re: Alternativa a variable PUBLIC

Postby Rick Lipkin » Sat Jun 08, 2019 5:25 pm

brakaman

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

Code: Select all  Expand view

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  Expand view

// 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  Expand view

cFileName := set(7)
 


Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2657
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Alternativa a variable PUBLIC

Postby jvtecheto » Sun Jun 09, 2019 8:44 am

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(r2104281802) + Borland 7.4 + FivEdit
User avatar
jvtecheto
 
Posts: 584
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Enrico Maria Giordano and 40 guests