3

I am using the BeforSignup in the AfterSignup unit in order to be able to call the email variable from within AfterSignup code, finally i enbcountred a problem because i want to make a button which opens the AfterSignup window using the code :

 AfterSignup.Show;

But the problem is that i am obliged to add the AfterSignup unit to the uses list of BeforeSignup and that is exactly what i can't do because i am alreadey using BeforeSignup to AfterSignup unit.

i receive an error saying, a reference of circular unit.

3

2 Answers 2

13

The easy solution would be to add unitA in the uses clause of the interface section of unitB and unitB in the uses clause of the implementation section of unitA

The better solution would be to break the dependency for both (or at least one) units.
You can break the dependency by either

  • moving all calls from unitA to unitB into unitB
  • adding a third, shared code unit, using both units A & B.
4

If your type declarations and variable declarations in the interface section of a unit require classes or variables in another unit, then you should be adding the required unit to the uses clause in the interface section.

However, if you only require the classes and variables in the implementation part of your unit, in implementation code, then you should be adding the required unit only to the uses clause in your implementation section.

If you have the unit already referenced in the interface section, you must not include it again in the implementation section.

If two units use each other only in the implementation section, there is no circular reference. You can also mix the uses, as long as two units don't use each other in the interface section (directly or indirectly), you won't have a circular reference.

So, based on your question, it seems like you should be using the units only in your implementation section, and there will be no circular reference.

1
  • Oddly, for as long as I've known about this, in Delphi 10.4, I'm getting circular reference errors even though one of them is used in the implementation section... Mar 4, 2022 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.