Uses with unit file path in unit file
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 8DC8977E7A7B469A开发者_运维知识库ACFE3CC77CA7075E\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)
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.
You have to configure your Project Options to put the "D3BF4E849ACC45249B990F802EFB1F15" and "F94C439C822E490DB228F2C16EF2C190" in the search paths. You can't specify the unit paths in code.
I am not sure whether this solves your problem, but there is the concept of namespaces, which allows you to put dots into unit names like this:
Rather than having the same filename in different directories ...
D3BF4E849ACC45249B990F802EFB1F15\UnitFile1.pas 8DC8977E7A7B469AACFE3CC77CA7075E\UnitFile1.pas
F94C439C822E490DB228F2C16EF2C190\UnitFile2.pas 14CEEFAFF1D64DDD8CBDEDD334D4A3FF\UnitFile2.pas
you could use a filename prefix:
D3BF4E849ACC45249B990F802EFB1F15.UnitFile1.pas 8DC8977E7A7B469AACFE3CC77CA7075E.UnitFile1.pas
F94C439C822E490DB228F2C16EF2C190.UnitFile2.pas 14CEEFAFF1D64DDD8CBDEDD334D4A3FF.UnitFile2.pas
You can then use the full filenames in the uses clause, e.g.:
uses
D3BF4E849ACC45249B990F802EFB1F15.UnitFile1;
Yes, this works with Delphi 7.
As far as I know, you cannot add two units with the same name to a project.
You can add the correct folder to the Project Options, or you can add the necessary units to the 'View - Project Manager' screen (right-click the project name and choose 'Add'. Pick the correct unit in the correct folder, and from than on you can use just the unit name in every form and other unit in your project.
Why you would want to use such cryptic folder names is really beyond me. I can't think of any, any reason why you would want to do this.
精彩评论