使用Uses语句。假设有如下语句:
uses aaa.bbb.unit1,unit2;
对于aaa.bbb.unit1已经明确指明,对于Unit2编译器会按照下面三个顺序来搜所名称空间Unit2
1 The current unit namespace (if any)
2 The project default namespace (if any)
3 Namespaces specified by compiler options
虽然对于外部编译器来讲,Unit名称的最后一节是看不到的也是不可区分的,但是在Delphi中,最后一节仍然是不可少的,所以uses语句中,需要包含最后一节,比如在Unit1 AAA.BB.Unit1中定义了Class1,在Unit AAA.BB.Unit2中要使用Class1就必须需在uses中引用全名uses AAA.BB.Unit1或者如果工程的默认名称空间是AAA.BB,也可以直接uses Unit1,不管怎么样,uses中Unit1是必不可少的。
在Delphi的帮助中这样写道:
Multiple units can be grouped together into one namespace using an extension of the in clause in the project source file. The file name string can list multiple unit source files in a semicolon-delimited list. uses
MyProgram.MyNamespace in ''''filepath/unit1.pas;otherpath/unit2.pas'''';
In this example, the namespace MyProgram.MyNamespace logically contains all the interface symbols from unit1 and unit2. Symbol names in a namespace must be unique, across all units in the namespace. In the example above, if unit1 and unit2 both define a global interface symbol named mySymbol, the compiler will report an error in the uses clause.
但是不管我怎样试验,重视编译错误,无法实现。
到目前为止,我还没有找到如何引用delphi生成的dll的方法。因为我一在delphi新的工程中添加一个(用Add reference菜单)delphi for .net编译的dll,然后编译,就会说致命错误,不能导入什么什么东西,请使用包,之类的。但是在VS.net中添加着dll却没有任何问题,程序也能正常运行。
到目前为止只找到一个暂时的解决方案,就是不生成library,用package代替,这样最终目标文件也是dll,而且我在VS中也能正常调用。