社区
Delphi
帖子详情
类的引用
ypyRock
2001-07-12 11:03:04
我分别在两个单元文件里定义了两个类,并分别实现了,但在这两个类的定义部分都
引用了了对方,USES里怎么写?
如:
unit1
uses
.........
ClassA=class
...
public
FCB:TClassB;
......
end.
unit2
uses
.........
ClassA=class
...
public
FCA:TClassA;
......
end.
两个单元里写引用会出现循环引用,我不想放在一个单元文件里。
...全文
47
2
打赏
收藏
微信扫一扫
点击复制链接
分享
下载分享明细
分享
举报
写回复
2 条
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
guig
2001-07-13
可以象下面那样改。
不过FCA用起来有些烦,那也没办法,谁叫你放着大路不走呀。
unit1
interface
uses unit2
.........
type
ClassA=class
...
public
FCB:TClassB;
......
end;
implementation
end.
unit2
interface
.........
type
ClassB=class
...
public
FCA:TObject;
constructor create;
......
end;
implementation
uses unit1;
constructor ClassB.create;
begin
...
FCA := ClassA.Create;//以后使用FCA时这样些ClassA(FCA)
end;
end.
打赏
举报
回复
赞
qkl
2001-07-12
看来是没有办法了:(
因为你的设计思想已经严重偏离 Delphi 的数据封装思想。
打赏
举报
回复
赞
相关推荐
相互
引用
的
类
如何定义?
两个
类
分别定义于两个Unit。 这两个Unit该如何相互
引用
? // file: Unit1.pas unit Unit1; interface type TObj1 = class() O2 : TObj2; end; implementation end. // file: Unit2.pas unit Unit2; interface type TObj2 = class() O1 : TObj1; end; implementation end.
Unit循环
引用
该如何解决?
以下两个文件产生了循环
引用
,该怎么办呢? 只能合并到一个文件中去吗? // file: Unit1.pas unit Unit1; interface uses Unit2; type TObj1 = class() O2 : TObj2; end; implementation end. // file: Unit2.pas unit Unit2; interface uses Unit1; type TObj2 = class() O1 : TObj1; end; implementatio
一个有关对象
引用
的问题
在Unit1中Class1的Interface中
引用
了Unit2中的Class2 在Unit2中Class2的Interface中
引用
了Unit1中的Class1 就是循环
引用
如果都在Uses中
引用
对方肯定会产生循环
引用
而通不过 于是就在Unit1中Class1的定义前加上了type Class2=class(TObject); 这样Unit1在implementation部分uses Unit2 而Unit2在interface中uses Unit1 循环
引用
是不会有了,但却提示我Unit1
如何去
引用
别的单元?
我写了一个单元,如下: unit Unit2; interface procedure hello; implementation procedure hello; begin showmessage('Hi,beginner!'); end; end. 现在有一个UNIT1单元,内有BUTTON1,当我点击BUTTON1时,调用hello过程,请问我应该如何去
引用
呢,我在UNIT1的单元中的implementation下写了uses unit2,但试运行时出现了hello没有定义.另外show
delphi 7中,
引用
其他单元中定义的
类
程序有Unit1,Unit2,我在Unit2定义了一个
类
.在Unit1中使用了uses Unit2,怎么在Unit1中
引用
这个
类
发帖
Delphi
加入
微信扫一扫
点击复制链接
分享社区
下载分享明细
5091
社区成员
26.2w+
社区内容
Delphi 开发及应用
社区管理员
申请成为版主
帖子事件
创建了帖子
2001-07-12 11:03
社区公告
暂无公告