Christian
Christian

Reputation: 7320

2 Runtime Packages: how can I use a unit from each other? (Delphi)

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.

Upvotes: 0

Views: 280

Answers (2)

Loren Pechtel
Loren Pechtel

Reputation: 9093

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?

Upvotes: 2

William Leader
William Leader

Reputation: 844

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.

Upvotes: 2

Related Questions