<snip>It is intended. It is not specific to Free Pascal, it is implemented in Delphi as well and it is a consequence of having an interface section separate from an implementation section. That is well documented, though not stated the way you did.
is this an intended function of Free Pascal that is neglected in the documentation for the language? That is, is this concept of a global variable being private to a unit an actual feature of free pascal, or are there nasty behind the scenes consequences to me using it? Thanks!
This works EXACTLY as I want it to work, I'm not having any difficulties. However, whenever I've tried to find this on the forums and on google, I've found no discussions about it. In Free Pascal, it seems like if you declare a variable between interface and implementation of unit A, then that variable is accessible to all units that import A. However, if you declare it after implementation but outside of procedures and functions, the variable is accessible within all procedures and functions, but is not accessible to units which import it. There are a huge amount of applications for this (at least in my opinion), but it doesn't even get a mention onThis rule is for all identifiers, not only variables and one of the core concepts of Object Pascal. It's also documented, namely in the language reference (https://www.freepascal.org/docs-html/current/ref/refsu91.html#x224-24600016.6.4).
https://wiki.freepascal.org/Scope (https://wiki.freepascal.org/Scope)
which surprises me. The reason for my post is, am I mistaken in some way, or is this an intended function of Free Pascal that is neglected in the documentation for the language? That is, is this concept of a global variable being private to a unit an actual feature of free pascal, or are there nasty behind the scenes consequences to me using it? Thanks!
Its also worth mentioning that while you CAN do it, you should not over do it. It is, sort of a global variable with all the problems a global variable brings.
In particular, consider very carefully before you have units all over the place modifying the value of one of those variables. Have seen posts where very skilled people suggest you only do this via properties, maybe read only properties so you can keep things tidy.
Davo
I have created a class with properties, but I have an array which holds objects of that class, and that is what I write this "global variable" as. In fact, I'd rather keep this array buried as one of the class's class properties, but I'm unsure how that would work memory wise, so I've decided to just make it more of a global variable in the class file.
In fact, I'd rather keep this array buried as one of the class's class properties,If the array is all of the same class type then to make it hidden you can do this in the defining unit: