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.

menjaraz
  • 7,551
  • 4
  • 41
  • 81
Rafik Bari
  • 4,867
  • 18
  • 73
  • 123
  • possible duplicate of [How to avoid circular unit reference?](http://stackoverflow.com/questions/1284959/how-to-avoid-circular-unit-reference) – Rob Kennedy Dec 21 '11 at 15:40
  • 1
    Rob, that question was different because they obviously needed the circular reference, but I think the OP is trying to avoid it. – Marcus Adams Dec 21 '11 at 15:58
  • Dude you really need to read a basic Pascal manual like this one: http://www.marcocantu.com/epascal/ – Warren P Dec 22 '11 at 21:39

2 Answers2

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.
Lieven Keersmaekers
  • 57,207
  • 13
  • 112
  • 146
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.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
  • 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... – Jerry Dodge Mar 04 '22 at 19:12