views:

62

answers:

3

Hi,

Lets assume we have 2 runtime packages, with 1 form in each one;

Pkg1 -> Unit1 (frm1)
Pkg2 -> Unit2 (frm2)

Now I want that they "know" each other. When pkg1 needs to know Unit2, we have to "require" Pkg2 in Pkg1. So now I can do a "uses" Unit2 and then do frm2.Show in Unit1 code.

But when I do the same thing in Pkg2 (set to require Pkg1), it does not compile, informing that Pgk2 already have a unit name Unit2 (I think is because Pkg1 is requiring Pkg2).

So, how to: in Unit1 do a "uses Unit2" and in Unit2 do a "uses Unit1"?

Thanks in advance.

+2  A: 

Either create a third package that contains everything common to the other two or you'll need to make one of the units available without using packages like adding them to the Delphi library path.

William Leader
I know that I can do it in both ways you suggest. I'm wondering if there is a way to do it as so simple as is looks.
Christian Almeida
@Christian: No, there isn't. You can't have circular dependencies among runtime packages, because their requirements list is strictly hierarchical.
Mason Wheeler
+1  A: 

Here is similar question: Defining types from other units in Delphi. Check the answers there.

zendar
+2  A: 

I would first look at your logic. Over the years I have come to realize that in almost all cases such a situation is bad code, generally a case of stuff that should be extracted out into a separate class or an abstract parent. Alternately, look at the command pattern--should they be sending each other commands rather than messing with each other?

Loren Pechtel