Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global variables in System.pas in applications which use DLLs

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?

like image 801
mjn Avatar asked Jan 19 '23 21:01

mjn


1 Answers

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.

like image 105
Andreas Hausladen Avatar answered Feb 21 '23 21:02

Andreas Hausladen