Uses with unit file path in unit file

tcak picture tcak · Jan 2, 2010 · Viewed 8.2k times · Source

I have problem. I ll try to explain it.

I have a unit which has a class and may will have new functions.

D3BF4E849ACC45249B990F802EFB1F15\UnitFile1.pas 8DC8977E7A7B469AACFE3CC77CA7075E\UnitFile1.pas

Both of them have same class: IClass_1 = class

Im using code numbers for different versions of this file.

Another unit file (UnitFile2.pas) uses that unit file (UnitFile1.pas).

Also, second unit file (UnitFile2.pas) has different versions.

F94C439C822E490DB228F2C16EF2C190\UnitFile2.pas 14CEEFAFF1D64DDD8CBDEDD334D4A3FF\UnitFile2.pas

Both of them have same class: IClass_2 = class(IClass_1)

Now problem starts;

"F94C439C822E490DB228F2C16EF2C190\UnitFile2.pas" needs "D3BF4E849ACC45249B990F802EFB1F15\UnitFile1.pas"

"14CEEFAFF1D64DDD8CBDEDD334D4A3FF\UnitFile2.pas" needs "8DC8977E7A7B469AACFE3CC77CA7075E\UnitFile1.pas"

But file names are same (I need a system like this. So they are same). And in unit file, delphi doesn't let me to write like that;

In file F94C439C822E490DB228F2C16EF2C190\UnitFile2.pas; uses UnitFile1 in 'D3BF4E849ACC45249B990F802EFB1F15\UnitFile1.pas';

I hope i could tell my problem. How can i tell the compiler which unit file i want to use with its path? (Im using Delphi-7)

Answer

Deltics picture Deltics · Jan 20, 2010

Give your unit names DIFFERENT names, you can then simply include both units in the project.

Then use a unit alias in your project options to create a "virtual unit name" which resolves to one or other of these actual units. In units which "use" one or other of these reference them by the unit alias - the "virtual name".

e.g. in the dpr:

  uses
    ...
    UnitFile1a in '....\UnitFile1a.pas',
    UnitFile1b in '....\UnitFile1b.pas',
    ...

In your units:

   uses
     UnitFile1;

In your project options a unit alias that is either:

   UnitFile1=UnitFile1a

OR

   UnitFile1=UnitFile1b

You can then build your project with whichever "UnitFile1?" unit is appropriate by simply changing the unit alias.