Circular reference problem
Posted on 2002-05-10
Hello, I have a problem with developing an elegant object oriented application in Delphi 6.
For example I need two classes TSalesperson and TCustomer where each instance of a salesperson needs to know what customers it is responsible for and each customer-instance need to know what salesperson they belong to.
The natural thing would be to do the following:
TSalesperson = class
TCustomer = class
When I do this and have each class residing in it's own unit I obviously get a circular reference warning from the compiler.
I can think of two workarounds for this problem:
1. Put both classes in the same unit
2. Make the fields of typ TObject and cast the references to the correct classes at runtime, in that case i could make one unit use(uses) the other in the implementation-section instead of in the interface and the compiler would be happy.
But I don't like either of these solutions because they will give me problems later on.
so my question is:
Is there any other way to solve this problem, perhaps by using interfaces or anything else? I'd be happy for any ideas.