Global Variable Problem
vanam srihari kumar
v_sriharikumar at yahoo.com
Tue Nov 15 11:44:28 CET 2005
Please find below the test code I am using
1) Makefile
******************************************************************************
PC=gpc
PFLAGS= -DSOLARIS
PLINK = -lgpc
VPATH = /home/kvsspl/
ModDemo3.o :ModDemo3.pas
$(PC) --automake -c $(PFLAGS) ModDemo3.pas
DemoMod3.o :DemoMod3.pas
$(PC) --automake -c $(PFLAGS) DemoMod3.pas
DemoMod4.o :DemoMod4.pas
$(PC) --automake -c $(PFLAGS) DemoMod4.pas
ModDemo3 :ModDemo3.o DemoMod3.o DemoMod4.o
$(PC) -o ModDemo3 ModDemo3.o DemoMod3.o DemoMod4.o
$(PLINK)
clean :
rm -f *.o *.out xtramain ModDemo3 *.gpi *.gpm
******************************************************************
2) DemoMod4.pas
******************************************************************
Module DemoMod4 (Output);
export DemoMod4=all;
type
FileNameString = string(80);
var PAS_DATABASE : FileNameString;
end;
end.
(*Is it possible to make these variables global,
without using export?*)
******************************************************************
3) DemoMod3.pas
******************************************************************
Module DemoMod3 (Output);
export DemoMod3=all;
procedure readenv;
end;
type
FileNameString = string(80);
var PAS_DATABASE : FileNameString;external;
uses gpc;
procedure readenv;
var
pascalEnv : string(80);
begin
pascalEnv:='PAS_DATABASE';
pascalEnv:=getenv(pascalEnv);
writeln('module pascalEnv = ',pascalEnv);
PAS_DATABASE :=
Copy(pascalEnv,1,Length(pascalEnv));
writeln('module PAS_DATABASE = ',PAS_DATABASE);
(*here PAS_DATABASE is printing nothing but
pascalEnv is ok*)
end;
end.
******************************************************************
4) ModDemo3.pas
******************************************************************
program ModDemo3 (Output);
uses gpc;
type
FileNameString = string(80);
procedure readenv;external;
var PAS_DATABASE : FileNameString;external;
begin
readenv;
writeln('program PAS_DATABASE = ',PAS_DATABASE);
(*here also PAS_DATABASE is printing nothing*)
end.
******************************************************************
what I want is to access 'PAS_DATABASE' variable in
all the modules,
when I set it in DemoMod3.pas line
PAS_DATABASE := Copy(pascalEnv,1,Length(pascalEnv))
Please suggest me as how to make it work?
Regards
Hari
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
More information about the Gpc
mailing list