如何导入 Pascal 代码?
执行 C 的 #include "code.h"
、Python 的 import code
等的 Pascal 方法是什么?
What's the Pascal way to do C's #include "code.h"
, Python's import code
, etc.?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Pascal 用于
导入其他模块。
Pascal uses
to import other modules.
虽然您可以显式地 {$INCLUDE 一个文件,但除了包含编译器开关的配置文件之外,很少这样做。我唯一一次这样做是很久以前,当时我想要两个版本的代码相同,只是一个版本使用仅协处理器的数据类型,而另一个版本则不使用。 (现在有多少人知道单精度和双精度类型过去需要昂贵的附加芯片或缓慢的仿真器?)
如果您在两个地方包含相同的代码,您将在 .EXE 中获得它的两个副本。如果在两个地方包含相同的类型定义,您将得到两个具有相同名称的类型,并且由于 Pascal 使用严格类型,它们将不匹配。
正如 Greg Hewgill 所说,正常的机制是使用您想要的文件。您使用的文件界面中出现的任何内容都是可见的,仅在实现中的任何内容都是不可见的。这是一个全有或全无的过程,您无需指定要引入的内容。想想 C# using 命令。
与 C# 版本不同,它是绝对强制的。您不能使用完全限定名称来绕过它。
While you can explicitly {$INCLUDE a file it's rarely done other than for configuration files containing compiler switches. The only time I've ever done it was long ago when I wanted two versions of the code identical except one used coprocessor-only datatypes and the other didn't. (And how many people these days even know that single and double types used to require either an expensive additional chip or a slow emulator?)
If you include the same code in two places you will get two copies of it in your .EXE. If you include the same type definition in two places you'll get two types with the same name and since Pascal uses strict typing they will not match.
The normal mechanic is as Greg Hewgill says, to use the file you want. Anything that appears in the interface of the file you use is visible, anything that's only in the implementation is not visible. This is an all-or-nothing process, you don't specify what you are bringing in. Think of the C# using command.
Unlike the C# version it's absolutely mandatory. You can't use fully qualified names to get around it.