Page 1 of 1

Variables PRIVATE

Posted: Thu Feb 12, 2009 12:05 pm
by triumvirato
Tengo dos PRG's:

Prueba.prg

Code: Select all

#include "FiveWin.ch"

memvar rut_bases

function Main()

   local oDlg
   private rut_bases := "Prueba de funcionamiento"
   
   probador()

   
return nil
prueba2.prg

Code: Select all

#include "FiveWin.ch"

function probador()

   MsgInfo( rut_bases )

return .T.
Cuando compilo, obtengo el siguiente warning:

--------------------Configuración: Pruebas - Debug--------------------
Harbour 1.0.1dev Intl. (Rev. 9361)
Copyright (c) 1999-2008, http://www.harbour-project.org/
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
Pruebas.c:
Harbour 1.0.1dev Intl. (Rev. 9361)
Copyright (c) 1999-2008, http://www.harbour-project.org/


C:\Pruebas\prueba2.prg(5) Warning W0001 Ambiguous reference: 'RUT_BASES'


Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
prueba2.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Pruebas.EXE - 0 error(es), 1 advertencia(s)

Se supone que una variable PRIVATE, puede ser llamada por cualquier procedure o por cualquier función definida por el usuario...
"The PRIVATE statement creates variables and arrays visible within the current and invoked procedures or user-defined functions"

Alguien ve qué estoy haciendo mal?

Gracias, Saludos!

Re: Variables PRIVATE

Posted: Thu Feb 12, 2009 12:14 pm
by Antonio Linares
David,

Incluye esta línea:

Code: Select all

#include "FiveWin.ch"

memvar rut_bases  // esta!

function probador()

   MsgInfo( rut_bases )

return .T.

Re: Variables PRIVATE

Posted: Thu Feb 12, 2009 12:24 pm
by triumvirato
Antonio,

Gracias por la solución, efectivamente poniendo ese memvar de la variable en ambos PRG's, no arroja el warning, pero... ¿hay que hacer la declaración memvar de la variable private en cada prg en el que se utilice o si ponemos un /N a la hora de compilar no haría falta?

Saludos!

Re: Variables PRIVATE

Posted: Thu Feb 12, 2009 12:41 pm
by Antonio Linares
David,

Con /v te evitarias ponerlo (creo).

Yo prefiero ponerlo y asi recordar de donde salen esas variables :-)

Re: Variables PRIVATE

Posted: Fri Feb 13, 2009 10:52 am
by triumvirato
Antonio,

Totalmente de acuerdo, es preferible tener que declarar todo, y quizás mucho mejor no usar variables private ni public, pero me encuentro con una migración de clipper y en un 80% esas variables venían así declaradas, por lo que primero prefiero hacerla funcional y luego ya ir encapsulando funciones, redefiniendo variables, etc., pero primero aprovechar todo lo que pueda del código anterior. Un auténtico lío sí, y más siendo novato con Fivewin y la mezcla sé que no va a quedar con una técnica de programación depurada, pero ahora prima más la funcionalidad.

He intentado colocar en la configuración del compilador de UEStudio el /v (creo que no es /v, sino /a) y el /a sin demasiado acierto. Esta es la configuración del compilador en UEStudio:

Code: Select all

# --------- xHarbour y FWH configuration --------
# --- general --------------------------------------
# $P  - project name
# $Pp - path to project directory
# $Pn - project name
# --- compile --------------------------------------
# $I  - input full name
# $Ip - input path
# $In - input name
# $Ie - input extension
# $O  - output file
# $Op - path to output file
# $On - output filename (without path)
# $Oe - output extension
# $R  - release/debug setting for compiler
# --- build ----------------------------------------
# $T  - target full name
# $Tp - target path
# $Tn - target name
# $O  - output file
# $Op - path to output file
# $On - output filename (without path)
# $Oe - output extension
# $R  - release/debug setting for linker

[Settings]
Target = 
Category&01 = DEFAULT RUN CONFIGURATION
Working Directory =.
Command Line Arguments =

Category&02 = Harbour Options
Automatic Memvar Declaration = no|yes
Variables Are Assumed = no|yes
Generate Preprocessed Output = no|yes
Warning Level = 1|2|3|4|0
User Include Path =
User Defines =

[b]Compiler Options = /a /v[/b]

Linker Options =

Excluded Files = Excludes

[SettingsInfo]
Target = Provides a space for you to specify an output file and location of the program that the linker creates.
Working Directory = Provides a space for you to specify the directory in which executing occurs. If you do not specify a directory, executing occurs in the directory where the executable is located.
Command Line Arguments = Provides a space for you to specify command-line arguments you want to pass to the program at startup.
Compiler Options = Provides a space for you to specify an additional compiler options.
User Defines = Shows the switches the tool will use to build. Use ';' as delimiter.
Linker Options = Provides a space for you to specify an additional linker options.
Excluded Files = This will exclude the file(s) included in this UE project group from the build.

[SettingsReps]
User Defines = @[;|-D%s]
Automatic Memvar Declaration = no=|yes=/a
Variables Are Assumed = no=|yes=/v
Generate Preprocessed Output = no=|yes=/p
User Include Path = ^^@[;|;%s]
User Include Path&1 = ^^@[;| /i%s]
Use Multi Thread Library = no|yes
Warning Level = @/w%s

[Variables]
FWH = c:\FWH
HPATH = c:\xHarbour
CPATH = c:\borland\bcc55

HPATHL = $(HPATH)\LIB
CPATHL = $(CPATH)\LIB

HOPT = /n /gc0 /q $(Compiler Options) /i$(HPATH)\INCLUDE $(User Include Path&1) $(User Defines) $(Automatic Memvar Declaration) $(Variables Are Assumed) $(Generate Preprocessed Output) $(Warning Level)
COPT = -O2 -M -c -v -I$(HPATH)\INCLUDE 

LOPT = -Gn -aa -Tpe -s -v
LIBS1 = $(FWH)\LIB\FiveHX.lib $(FWH)\LIB\FiveHC.lib 
LIBS2 =  $(HPATHL)\rtl.lib $(HPATHL)\vm.lib $(HPATHL)\gtgui.lib $(HPATHL)\lang.lib $(HPATHL)\macro.lib $(HPATHL)\rdd.lib $(HPATHL)\dbfcdx.lib $(HPATHL)\dbfntx.lib $(HPATHL)\dbffpt.lib $(HPATHL)\hbsix.lib $(HPATHL)\debug.lib $(HPATHL)\common.lib $(HPATHL)\pp.lib $(HPATHL)\codepage.lib $(HPATHL)\pcrepos.lib
LIBS3 = $(CPATHL)\cw32.lib $(CPATHL)\import32.lib $(CPATHL)\psdk\odbc32.lib $(CPATHL)\psdk\msimg32.lib $(CPATHL)\psdk\nddeapi.lib $(CPATHL)\psdk\iphlpapi.lib  $(CPATHL)\psdk\rasapi32.lib
LIBS = $(LIBS1) $(LIBS2) $(LIBS3)

[Environment]
PATH = $(HPATH)\BIN;$(CPATH)\BIN;%PATH%
INCLUDE = $(HPATH)\INCLUDE;$(CPATH)\INCLUDE;$(FWH)\INCLUDE
LIB = $(HPATH)\LIB;$(CPATH)\LIB
BuildMode = %UESMode%

[General]
TargetExt = .EXE
ReleaseOut = Release
DebugOut = Debug
UseFullPaths = 1
UseDosNames = 1
Excludes = $(Excluded Files)
GenerateEDGroup=$(External Dependencies)
.CPP = .C

[MakeCommands]
run = Execute Application
makef = Show Makefile

[Execute Application]
Title = Execute $T
Cmd0 = $(Command Line Arguments)
Depends = $T
ShowWindow = 1
DisplayConsole = $(DCon)

[Show Makefile]
Title=Show makefile
Cmd0=uestudio makefile
ShowWindow=1
DisplayConsole=0

[InsertFiles]

[FileGroups]
FGO = .obj;
FGR = .res;
FGL = .lib;
FGD = .def;

[GroupFormats]
FGO = %s
FGR = %s
FGL = %s

[Build]
Out = $T
Depends = $FGO $FGR
DebugFlag = 
ReleaseFlag = 
Cmd0 = ilink32 $(LOPT) c0w32.obj $FGO, $T,, $(LIBS),, $FGR

[.PRG]
Out = $In.c
DebugFlag = /b
ReleaseFlag = /l
Cmd0 = harbour $I $(HOPT) $R /o$O 

IncFiles = 1
CaseSensitive = 0
IncDirs = .;$(INCLUDE);
IncKeyWords = #include;
Comments = /*.*/.//.eol.

[.C]
Out = $In.obj
Cmd0 = bcc32 $(COPT) -o$O $I

[.RC]
Out = $In.res
Cmd0 = brc32 -r -fo$O $I

IncFiles = 1
CaseSensitive = 0
IncDirs = .;$(INCLUDE);
IncKeyWords = #include;
Comments = /*.*/.//.eol.

Dime si es correcto donde tengo colocados el /a /v por favor, pues voy a golpes últimamente con el UEStudio.

Gracias!

Re: Variables PRIVATE

Posted: Fri Feb 13, 2009 11:05 am
by Antonio Linares
David,

Fijate que en ese fichero de configuración ya tienes el poder selecionar esas opciones desde el UEStudio:

Automatic Memvar Declaration = no=|yes=/a
Variables Are Assumed = no=|yes=/v

Re: Variables PRIVATE

Posted: Fri Feb 13, 2009 11:37 am
by triumvirato
Antonio,

Ok... me faltaba descubrir en el menú para qué servía "Establecer opciones del compilador". :oops:

De todas formas, compilando con ambos parámetros sigo con el warning:

C:\PROC_1.PRG(165) Warning W0002 Ambiguous reference, assuming memvar: 'CLI_RAC'

Saludos!

Re: Variables PRIVATE

Posted: Mon Feb 16, 2009 9:15 pm
by ADBLANCO
Para conversiones de este tipo, Yo prefiero definir esas memvar en un .ch, y despues hacer un #include

Re: Variables PRIVATE

Posted: Tue Feb 17, 2009 4:45 am
by Manuel Valdenebro
triumvirato wrote: De todas formas, compilando con ambos parámetros sigo con el warning:

C:\PROC_1.PRG(165) Warning W0002 Ambiguous reference, assuming memvar: 'CLI_RAC'
Cuentas al principio, que estás convirtiendo un código-Clipper en FiveWin. Está es mi opinión:

FUNCTION Main()
Local .......
Local ......

Memvar var1, var2, var3, var4 .....

PUBLIC var1, var2, var3, var4 ..... // esto seguramente te falta

- - - - - - - - - - - - - -

Despues, en cada función, solo tienes que declarar las memvar que uses en ESA funcion. Por ejemplo:

FUNCTION CLIENTES()
Local ....
Memvar var2

-------

FUNCTION IMPRIMIR()
local ...
memvar var3, var4


Espero que con esto desaparezcan los "warning".

Re: Variables PRIVATE

Posted: Tue Feb 17, 2009 7:59 am
by triumvirato
ADBLANCO wrote:Para conversiones de este tipo, Yo prefiero definir esas memvar en un .ch, y despues hacer un #include
Es una solución que no se me había ocurrido... gracias adblanco.
Manuel Valdenebro wrote:
triumvirato wrote: De todas formas, compilando con ambos parámetros sigo con el warning:

C:\PROC_1.PRG(165) Warning W0002 Ambiguous reference, assuming memvar: 'CLI_RAC'
Cuentas al principio, que estás convirtiendo un código-Clipper en FiveWin. Está es mi opinión:

FUNCTION Main()
Local .......
Local ......

Memvar var1, var2, var3, var4 .....

PUBLIC var1, var2, var3, var4 ..... // esto seguramente te falta

- - - - - - - - - - - - - -

Despues, en cada función, solo tienes que declarar las memvar que uses en ESA funcion. Por ejemplo:

FUNCTION CLIENTES()
Local ....
Memvar var2

-------

FUNCTION IMPRIMIR()
local ...
memvar var3, var4


Espero que con esto desaparezcan los "warning".
Gracias Manuel. Efectivamente haciendo así la declaración memvar desaparecen los warning, pero tengo el inconveniente de que son muchísimos. Por eso buscaba una solución (momentánea, hasta avanzar en el desarrollo y encapsular todo un poco más) a través de compilador, ya que en teoría, al compilar con el parámetro /a, debería hacer la declaración automáticamente, como dice la documentación: (extraído de http://www.ousob.com/ng/harbour/ng69341.php)

The Harbour command line options:
=================================

/a automatic memvar declaration
=================

This causes all variables declared by PARAMETER, PRIVATE or
PUBLIC statements to be automatically declared as MEMVAR
variables.

Pues compilando con /a, los warning siguen apareciendo de esta forma:
C:\Gesco\IMPORT.PRG(3486) Warning W0001 Ambiguous reference: 'RUT_DEF'

Ahora bien, si compilamos con el parámetro /v:
/v variables are assumed M=>
=================

All undeclared or unaliased variables are assumed MEMVAR
variables (private or public variables). If this switch is not
used then the scope of such variables is checked at runtime.

los warning aparecen del modo:
C:\Gesco\IMPORT.PRG(3486) Warning W0002 Ambiguous reference, assuming memvar: 'RUT_DEF'
Se supone que las está asumiendo como memvar.

Creo que tengo bastante cacao-merengao todavía con esto y no soy capaz de darle solución para que asuma las variables public y privita como memvar y no muestre los warning.

Saludos!

Re: Variables PRIVATE

Posted: Tue Feb 17, 2009 11:14 am
by anserkk
Have you tried /W0 (W zero)
I have used this to avoid the warning message 'Warning W0002 Ambiguous reference'
-----------------------------------------------
¿Ha intentado / W0 (W cero)
He utilizado esto para evitar el mensaje de advertencia 'Warning W0002 Ambiguous reference'

Saludos

Anser

Re: Variables PRIVATE

Posted: Thu Feb 19, 2009 8:01 am
by triumvirato
anserkk wrote:Have you tried /W0 (W zero)
I have used this to avoid the warning message 'Warning W0002 Ambiguous reference'
-----------------------------------------------
¿Ha intentado / W0 (W cero)
He utilizado esto para evitar el mensaje de advertencia 'Warning W0002 Ambiguous reference'

Saludos

Anser
Anser,

Many thanks for your answer. The problem of compiling with the /w0 parameter is that all the warnings messages are disallowed, and i only want to disallow the message 'Warning W0002 Ambiguous reference'. I think the only solution is to declare the varibles as Manuel post here.

Muchas gracias por tu sugerencia. El problema de compilar con el parametro /w0 es que se desactivan todos los mensajes del warning y solamente quiero desactivar los del tipo 'Warning W0002 Ambiguous reference'. Creoque la única solución es declarar las variables como posteo Manuel.

Saludos!