这本来是我的一个问题,谢谢ThinkX、blow_jj 、Maconel 、hy1080 的解答,现整理一下答案。
使用全局变量应该将变量定义在.c中,在.h中extern。在需要使用变量的地方,包含.h就行了。还要注意自己给.h文件加些预编译,可以直接新建unit,预编译会自动生成。
例如在global.cpp和global.h中定义全局变量 在global.cpp中这样写: #include "global.h" //-------------------- int a; bool b; long c; AnsiString d;
在global.h中这样写: extern int a; extern bool b; extern long c; extern AnsiString d;
在要使用全局变量的地方#include "global.h"就行了 
|