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
vanam srihari kumar a écrit:
The following works as you expect
-------------------------------------------------------- program ModDemo3 (Output);
import DemoMod4; DemoMod3;
begin readenv; writeln('program PAS_DATABASE = ',PAS_DATABASE); (*here also PAS_DATABASE is printing nothing*) end. -------------------------------------------------------- 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?*) ---------------------------------------------------------- Module DemoMod3 (Output);
export DemoMod3=all; procedure readenv;
end;
import gpc; DemoMod4;
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. ----------------------------------------------------------
if you type
gp ModDemo3.pas set PAS_DATABASE=toto < have you done that ? ModDemo3
module pascalEnv = toto module PAS_DATABASE = toto program PAS_DATABASE = toto
Maurice
On Tue, Nov 15, 2005 at 02:44:28AM -0800, vanam srihari kumar wrote:
Please find below the test code I am using
- 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
- 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?*)
- DemoMod3.pas
Module DemoMod3 (Output); export DemoMod3=all; procedure readenv; end; type FileNameString = string(80); var PAS_DATABASE : FileNameString;external; uses gpc;
Do not redefine the type and variable, import them:
Module DemoMod3 (Output);
export DemoMod3=all; procedure readenv; end;
uses DemoMod4, gpc;
Please read the documentation, as you seem to misunderstand how the concept of modules is supposed to work.
Emil Jerabek
Emil Jerabek wrote:
Module DemoMod3 (Output); export DemoMod3=all; procedure readenv; end; type FileNameString = string(80); var PAS_DATABASE : FileNameString;external; uses gpc;
Do not redefine the type and variable, import them:
Module DemoMod3 (Output);
Yes (and the procedure). I know, the bad influence of C ...
But apart from this, there is unfortunately a bug in gpc-2.1 which was fixed meanwhile, and which is probably the cause of the problem here:
@item 20030321: variables declared in interfaces of modules are not initialized (capacity of strings etc.) (daj3.pas, sven14c.pas, nick1.pas)
So my recommendation is to upgrade GPC. Even though the most recent releases are labelled alpha, they're not much less stable than 2.1 (probably even more stable, as many bugs, such as this one, have been found and fixed since then). The most recent one is http://www.math.uni.wroc.pl/~hebisch/gpc/gpc-20051104.tar.bz2
Side note:
PAS_DATABASE := Copy(pascalEnv,1,Length(pascalEnv))
The Copy here is a nop. Perhaps you did this in order to debug the bug above. Otherwise, you could just say PAS_DATABASE := pascalEnv.
Frank