与单元文件中的单元文件路径一起使用
我有问题。我会尽力解释一下。
我有一个单元,它有一个类,并且可能会有新的功能。
D3BF4E849ACC45249B990F802EFB1F15\UnitFile1.pas 8DC8977E7A7B469AACFE3CC77CA7075E\UnitFile1.pas
它们都具有相同的类: IClass_1 = 类
Im 使用此文件的不同版本的代码号。
另一个单元文件 (UnitFile2.pas) 使用该单元文件 (UnitFile1.pas)。
此外,第二个单元文件(UnitFile2.pas)有不同的版本。
F94C439C822E490DB228F2C16EF2C190\UnitFile2.pas 14CEEFAFF1D64DDD8CBDEDD334D4A3FF\UnitFile2.pas
他们两个都有相同的类: IClass_2 = class(IClass_1)
现在问题开始了;
“F94C439C822E490DB228F2C16EF2C190\UnitFile2.pas” 需要 “D3BF4E849ACC45249B990F802EFB1F15\UnitFile1.pas”
“14CEEFAFF1D64DDD8CBDEDD334D4A3FF\UnitFile2.pas” 需要 “8DC8977E7A7B469AACFE3CC77CA7075E\UnitFile1.pas”
但是文件名是相同的(我需要这样的系统。所以它们是相同的)。在单元文件中,delphi不允许我这样写;
在文件F94C439C822E490DB228F2C16EF2C190\UnitFile2.pas中; 在“D3BF4E849ACC45249B990F802EFB1F15\UnitFile1.pas”中使用UnitFile1;
我希望我能说出我的问题。我如何告诉编译器我想使用哪个单元文件及其路径? (我使用Delphi-7)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为您的单元命名不同的名称,然后您可以简单地将这两个单元包含在项目中。
然后在项目选项中使用单位别名来创建一个“虚拟单位名称”,该名称可解析为这些实际单位中的一个或另一个。在“使用”其中一个或另一个的单元中,通过单元别名(“虚拟名称”)来引用它们。
例如,在 dpr 中:
在您的单位中:
在您的项目选项中,单位别名可以是:
或者
您可以使用“UnitFile1?”中的任何一个来构建您的项目只需更改单位别名即可使用单位。
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:
In your units:
In your project options a unit alias that is either:
OR
You can then build your project with whichever "UnitFile1?" unit is appropriate by simply changing the unit alias.
您必须配置项目选项,以将“D3BF4E849ACC45249B990F802EFB1F15”和“F94C439C822E490DB228F2C16EF2C190”放入搜索路径中。您无法在代码中指定单元路径。
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.
我不确定这是否解决了您的问题,但是存在命名空间的概念,它允许您将点放入单元名称中,如下所示:
而不是在不同的目录中使用相同的文件名...
D3BF4E849ACC45249B990F802EFB1F15\UnitFile1.pas
8DC8977E7A7B469AACFE3CC77CA7075E\UnitFile1.pas
F94C439C822E490DB228F2C16EF2C190\UnitFile2.pas
14CEEFAFF1D64DDD8CBDEDD334D4A3FF\UnitFile2.pas
您可以使用文件名前缀:
D3BF4E849ACC45249B990F802EFB1F15.UnitFile1.pas
8DC8977E7A7B469AACFE3CC77CA7075E.UnitFile1.pas
F94C439C822E490DB228F2C16EF2C190.UnitFile2.pas
14CEEFAFF1D64DDD8CBDEDD334D4A3FF.UnitFile2.pas
然后您可以在uses子句中使用完整的文件名,例如:
是的,这适用于Delphi 7。
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.:
Yes, this works with Delphi 7.
据我所知,您不能将两个同名的单元添加到一个项目中。
您可以将正确的文件夹添加到项目选项,也可以将必要的单元添加到“查看 - 项目管理器”屏幕(右键单击项目名称并选择“添加”< > 在正确的文件夹中选择正确的单位,然后您就可以在每个表单和项目中的其他单位中仅使用该单位名称。
/ strong 想要使用如此神秘的文件夹名称确实超出了我的范围,我想不出任何原因。
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.