使用 DLL 的应用程序中 System.pas 中的全局变量
如果Delphi应用程序使用DLL(也是用Delphi创建的),System.pas中声明的变量是否会有多个版本?
我刚刚读过 如何确定我是否作为控制台应用程序运行? (Delphi on Win32) 并且注释解释了可以有多个版本,例如 System.IsConsole,它们具有不同的值 - EXE 中为 True,DLL 中为 False(如果使用 $APPTYPE CONSOLE 编译) )。
但其他变量似乎是为应用程序范围的值设计的,例如
MainInstance: LongWord; { Handle of the main(.EXE) HInstance }
CPUCount: Integer; { Number of CPU Cores detected }
开发人员如何查看哪些值将在应用程序级别分配,哪些变量是特定于模块的(因此在 DLL 和 EXE 中可以有不同的值)?
或者我误解了这些全局变量?例如 System.BeginThread 的文档说它设置全局变量 < a href="http://docwiki.embarcadero.com/VCL/en/System.IsMultiThread" rel="nofollow noreferrer">System.IsMultiThread - 但它怎么可能是一个全局变量并且System.IsConsole 不是吗?
If Delphi applications use DLLs (also created with Delphi), will there be multiple versions of the variables declared in System.pas?
I have just read How to determine if I'm running as a console app? (Delphi on Win32) and the comment explains that there can be multiple versions of, for example, System.IsConsole which have different values - True in the EXE and False in the DLL (if it was compiled using $APPTYPE CONSOLE).
But other variables seem to be designed for application-wide values, for example
MainInstance: LongWord; { Handle of the main(.EXE) HInstance }
CPUCount: Integer; { Number of CPU Cores detected }
How can developers see which values will be assigned on application level, and which variables are module-specific (and so can have different values in DLLs and EXE)?
Or do I misunderstand these global variables? For example the documentation for System.BeginThread says that it sets the global variable System.IsMultiThread - but how can it be a global variable and System.IsConsole not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您将 DLL 链接到 RTL.bpl 或包含系统单元的用户定义的“主”BPL,否则您的 DLL 将拥有自己的一组全局系统变量。它们在加载 DLL 时初始化。 CPUCount 不需要 EXE 来填充它。 DLL 通过向 Windows 询问其值来填充它。 DLL 还有它自己的 IsMultiThread 变量(除非您将 DLL 链接到 RTL.bpl ...)。因此,您的 EXE 可以有多个线程,并且 DLL IsMultiThread 变量仍然显示 False。
Unless you link your DLL against the RTL.bpl or a user defined "master" BPL that contains the System unit, your DLL will have its own set of global System variables. They are initialized when the DLL is loaded. CPUCount doesn't need the EXE to fill it. The DLL fills it by asking Windows about its value. The DLL has also its own IsMultiThread variable (unless you link your DLL against the RTL.bpl ...). So your EXE can have multiple threads and the DLLs IsMultiThread variable still says False.