开发者

Global variables in System.pas in applications which use DLLs

开发者 https://www.devze.com 2023-03-30 11:09 出处:网络
If Delphi applications use DLLs (also created with Delphi), will there be multiple versions of the variables declared in System.pas?

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 val开发者_C百科ues, 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消