2012-11-18 126 views
0

更多Pascal困境。Pascal:完全将模块导入当前范围

说我有2台,MainUnitExampleClass

MainUnit:

Unit MainUnit; 

interface 

Uses ExampleClass; 

function ReturnFive: Integer; 

implementation 

function ReturnFive: Integer; 
begin 
    ReturnFive := 5; 
end; 

begin 
end. 

ExampleClass中:现在

Unit ExampleClass; 

{$mode objfpc} 

interface 

type 
    ClassThing = Class 
    SampleValue: Integer; 
    end; 


implementation 

begin 
end. 

,我想只导入MainUnit,但仍然能够使用ClassThingMainUnituses ExampleClass,但当您导入MainUnit时,ClassThing不可用。

我真的不想只是useExampleClass连同MainUnit,我宁愿保留在一个uses声明。

你是如何做到这一点的?

+0

您不能。但是,如果您只需要访问ClassThing,则不必使用* MainUnit。 –

+0

@SertacAkyuz所以你只需要将所有东西打包到一个文件中,或者使用一堆不同的模块? :( –

+0

是的,这是正确的。 –

回答

1

type ClassThing = ExampleCLass.ClassThing; 

在mainunit的接口。

的原则也适用于consts,但只有“真实”的人(不是类型的人这是更初始化增值经销商):

const myconst = unitname.myconst; 

几乎所有我的大量使用类型相似的别名,所以我可以轻松地在不改变所有商业代码单元中的使用条款的情况下移动它们的位置