Page 1 of 1

STATIC Variables

Posted: Tue Apr 21, 2009 11:09 am
by ohaldi
I'm still learning HMG and have a small problem with STATIC variables.
I don't think that is a HMG problem. Tell me if it's not allowed to ask no HMG question!

I have a small problem with STATIC variables. I used the compile.bat batch for this example.

If I compile this test.prg sample alone, it is OK. No error!
Example1 (test.prg):
Static Test := {}
FUNCTION Test()
Return nil

If I include this test.prg in the main.prg like this:
Example2 (main.prg):
set Procedure to test

FUNCTION Main()
Return nil

Then I get this error:
test.prg(1) Error E0004 STATIC declaration follows executable statement

Re: STATIC Variables

Posted: Tue Apr 21, 2009 12:32 pm
by dhaine_adp
I have a small problem with STATIC variables. I used the compile.bat batch for this example.
IMHO, your getting this problem because of the order of declaration of commands:

set procedure to.... follows an executable statement. Supposed to be you have to call the routine after the main() declaration.

You have two options to resolved your problem:

(1) - move the static declaration of variable to main()
(2) - revised the code as follows:


*set procedure to test -->> you would get the error because this line was executed first and followed by a statement, in this case it is a function declaration...... removed this line and compile them
************
function main()
test(1)
return nil

************
function test(x)
static aTest := {}
return nil

Whether that is in one prg source code or in two different source code, I believed that would fix the problem.

You don't have to used the command statement SET PROCEDURE TO because when you linked the two files the procedure or function is available at run-time.
Here is another example
***************
function main()

local nAbc := 1

? Test(nAbc)
inkey(0)

return nil

*****************
function Test( nX )

static nVar

nVar := nX + 1

return nVar

Compile them in two separate .prg file or in one prg file does not matter. If you prefer to use HMG IDE make sure that you thick mark console mode on the preference. Otherwise, you would not see any output though the program is running but you cannot see anything. Fire-up the task manager to kill it (main.exe)


Regards,

Danny

Re: STATIC Variables

Posted: Tue Apr 21, 2009 6:54 pm
by ohaldi
Many thanks for your quick help.
OK, now I understand.
function test(x)
static aTest := {}
return nil
This solution is good but this aTest array must be visible in the whole prg.
Raison that I placed it at the top.!

In fact I used "set procedure to" to compile 4 prg's at one time. I think, I have to switch to a MAKE solution.
I like to have a simple solution with a batch file. I use this solution with clipper, because from my editor (TextPad) I
have a button who call batch named CompAll.bat. This batch use first a make to find out witch prg's have to be compiled
If the compiler find any error then I only have to click on this error line to be placed correctly in the source.
If no error then the linker is called. Is somebody have a good sample for HMG, it will help me.
Thanks in advance.

Re: STATIC Variables

Posted: Sun May 17, 2009 7:50 am
by ohaldi
Here the simple solution to compile 4 prg's individually.
This solve problem with STATIC variables.
My CompAll.Bat script:

SET PATH=c:\HMG\mingw\bin;C:\HMG\MINGW\LIBEXEC\GCC\MINGW32\3.4.5
SET MINGW=c:\HMG\mingw
SET HRB_DIR=c:\HMG\harbour
SET OBJ_DIR=c:\HMG\KALGA32\obj\
SET MINIGUI_INSTALL=c:\HMG

%HRB_DIR%\bin\harbour kalga.prg -n -i%HRB_DIR%\include;%MINIGUI_INSTALL%\include; -o%OBJ_DIR%
%HRB_DIR%\bin\harbour adresse.prg -n -i%HRB_DIR%\include;%MINIGUI_INSTALL%\include; -o%OBJ_DIR%
%HRB_DIR%\bin\harbour proce.prg -n -i%HRB_DIR%\include;%MINIGUI_INSTALL%\include; -o%OBJ_DIR%
%HRB_DIR%\bin\harbour reorgcmx.prg -n -i%HRB_DIR%\include;%MINIGUI_INSTALL%\include; -o%OBJ_DIR%

gcc -I. -I%HRB_DIR%\include -mno-cygwin -Wall -c %OBJ_DIR%kalga.c -o %OBJ_DIR%kalga.o
gcc -I. -I%HRB_DIR%\include -mno-cygwin -Wall -c %OBJ_DIR%adresse.c -o %OBJ_DIR%adresse.o
gcc -I. -I%HRB_DIR%\include -mno-cygwin -Wall -c %OBJ_DIR%proce.c -o %OBJ_DIR%proce.o
gcc -I. -I%HRB_DIR%\include -mno-cygwin -Wall -c %OBJ_DIR%reorgcmx.c -o %OBJ_DIR%reorgcmx.o

gcc -Wall -o kalga %OBJ_DIR%kalga.o %OBJ_DIR%adresse.o %OBJ_DIR%proce.o %OBJ_DIR%reorgcmx.o %MINIGUI_INSTALL%\resources\minigui.o -L%MINGW%\lib -L%HRB_DIR%\lib -L%MINIGUI_INSTALL%\lib -mno-cygwin -Wl,--start-group -lcnl -lgtwin -lminigui -ldll -luser32 -lwinspool -lcomctl32 -lcomdlg32 -lgdi32 -lole32 -loleaut32 -luuid -lwinmm -lvfw32 -lwsock32 -lgraph -ledit -lreport -lini -leditex -lcrypt -lhbapollo -lhbbmcdx -lhbbtree -lhbclipsm -lhbcommon -lhbcpage -lhbcplr -lhbct -lhbcurl -lhbfbird -lhbgd -lhbhpdf -lhbhsx -lhblang -lhbmacro -lhbmainstd -lhbmisc -lhbmsql -lhbmysql -lmysqldll -lhbmzip -lhbnf -lhbodbc -lodbc32 -lhbpcre -lhbpgsql -lhbpp -lhbrdd -lhbrtl -lhbsix -lhbsqlit3 -lhbtip -lhbusrrdd -lhbvm -lhbvpdf -lhbw32 -lhbzlib -lrddado -lrddads -lrddcdx -lrddfpt -lrddntx -lxhb -Wl,--end-group

Re: STATIC Variables

Posted: Sun May 17, 2009 8:02 am
by Rathinagiri
Thanks for the info.