Sorry this is a very newbie question.
We have this massive application I am doing maintenance on. It has 5 different forms. We put our global variables in one unit (uGlobal). But i can’t seem to access it from the data unit (uData).
I have this:
Unit uGlobal
type
TmyType: (alpha, beta);
...
Unit uGlobal
Stuff: TmyType <- error, undeclared indentifier
When i try to put uGlobal in the uses section of uData, it complains of a circular reference. So, kinda clueless here. They are both in the same project. This is using BDS 2006.
You have a circular reference because you have things in
uGlobalthat want to make use of things inuDataand vice-versa. Circular references are a big concern in large projects because they greatly increase complexity – if you have circular dependencies, it becomes more like one BIGGER unit. I suspect you have a long way to go before your project can be considered large, let alone “massive”. 😉You have 2 possible solutions:
Keeping the circular dependency
David has already given the answer: At least one of the units must use the other from the implementation section.
uData interfaceand referenced that inuGlobal interface, then the interface ofuGlobalneedsuDataand will need a corresponding uses clause.uData implementationthat’s referenced in anywhereuGlobal, then that declaration inuData implementationmust be moved to the interface section.uGlobal interfacemust it’s only referenced from the implementation section ofuDatathen that uses clause will be fine in the implementation section.Remove Circular Dependency
Removing the circular dependency requires breaking your units down into smaller ones that are more manageable. To do this, you must understand the dependencies between each of the things in your application.
For example:
uGlobaldeclares A and CuDatadeclares B which needs CAll you have to do in this case is declare a new unit at move C in there.
uGlobalanduDatawill useuNewUnitDisclaimer
I am not in any way advocating your approach with uGlobal. In fact it is a very bad idea and will bite you big time on 2 fronts when your projects starts to get large. Unfortunately the explanation is a mammoth answer in itself.