TThread 中的继承问题,在 D2010 中的工作方式似乎与 D7 不同
在我的应用程序中,我有两个线程对象(Outer 和 Sash),它们继承自 TThread 类型的基本线程对象 (FrameObject)。这在 D7 中一切正常。该应用程序需要扩展,我借此机会将其移至 D2010 - 然而,当我尝试编译 Delphi 时,抱怨 FrameObject Create 方法声明与之前的声明不同。
类类型和构造函数如下所示;
TFrameObject = class(TThread)
constructor TFrameObject.Create(BuildType: TBuildType; OnBatchStep: TBatchNotify; OnThreadComplete: TNotifyTermination);
begin
inherited Create(True);
...
end;
TOuter = class (TFrameObject)
constructor Create(BuildType: TBuildType; OnBatchStep: TBatchNotify; OnThreadComplete: TNotifyTermination; ExceptionHandler: TExceptionHandler);
begin
inherited create(BuildType, OnBatchStep, OnThreadComplete);
fExceptionHandler := ExceptionHandler;
...
end;
TSash = class (TFrameObject)
constructor Create(BuildType: TBuildType; OnBatchStep: TBatchNotify; OnThreadComplete: TNotifyTermination; ExceptionHandler: TExceptionHandler);
begin
inherited create(BuildType, OnBatchStep, OnThreadComplete);
fExceptionHandler := ExceptionHandler;
...
end;
D2010 代码是 D7 源文件的直接副本,正如我所说,这一切在 D7 中都能正常工作(也许不应该!) - 那么我哪里出错了?
In my Application I have two thread objects (Outer and Sash) that inherit from a base thread object (FrameObject) of type TThread. This all works fine in D7. The application needs to be extended and I am taking this opportunity to move it to D2010 - however when I try to compile Delphi complains that the FrameObject Create method declaration differs from the previous declaration.
The Class types and Constructors are shown below;
TFrameObject = class(TThread)
constructor TFrameObject.Create(BuildType: TBuildType; OnBatchStep: TBatchNotify; OnThreadComplete: TNotifyTermination);
begin
inherited Create(True);
...
end;
TOuter = class (TFrameObject)
constructor Create(BuildType: TBuildType; OnBatchStep: TBatchNotify; OnThreadComplete: TNotifyTermination; ExceptionHandler: TExceptionHandler);
begin
inherited create(BuildType, OnBatchStep, OnThreadComplete);
fExceptionHandler := ExceptionHandler;
...
end;
TSash = class (TFrameObject)
constructor Create(BuildType: TBuildType; OnBatchStep: TBatchNotify; OnThreadComplete: TNotifyTermination; ExceptionHandler: TExceptionHandler);
begin
inherited create(BuildType, OnBatchStep, OnThreadComplete);
fExceptionHandler := ExceptionHandler;
...
end;
The D2010 code is a direct copy of the D7 source files and as I say, this all works fine in D7 (perhaps it shouldn't!) - so where am I going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查在多个单元中声明的类型,其中一个在接口中使用,另一个在实现部分中使用,例如
TFrameObject
声明中的TBuildType
(在接口部分中) ) 将解析为UnitA.TBuildType
并实现为UnitB.TBuildType
。Check for types declared in multiple units where one of them is used in the interface and another in the implementation section, so for example
TBuildType
in yourTFrameObject
declaration (in the interface section) would resolve toUnitA.TBuildType
and implementation toUnitB.TBuildType
.我对这里发生的情况的猜测是,实现部分中的
uses
子句声明了TBuildType
、TBatchNotify
或TNotifyTermination< /code> 这与您声明构造函数的接口部分中使用的不同。
一种快速检查方法是在 TFrameObject.Create 的实现中完全限定这些类型。
My guess at to what is happening here is that the
uses
clause in your implementation section is declaring aTBuildType
,TBatchNotify
orTNotifyTermination
that is different from the one used in your interface section where you declare the constructor.A quick way to check would be to fully qualify those types in the implementation of
TFrameObject.Create
.根据其他答案,最可能的解释是,实现部分中使用的单元中新引入的类型隐藏了接口部分中使用或声明的同名类型。
但是,与以前的答案不同,由于问题仅发生在 D2010 而不是 D7 中,因此我怀疑 TExceptionHandler 类型的 ExceptionHandler 参数,因为 D2010 包含声明了此名称的类型在 ToolsAPI\IStreams 中。
您可以在实现部分限定名称:
其中“MyUnit”是包含您希望使用的“真实”TExceptionHandler 的单元的名称。
或者,您可以在接口部分中为类型设置别名,并更改参数列表,以便在该单元的接口和实现中一致使用别名类型:
As per other answers, a newly introduction type in a unit used in the implementation section hiding a type of the same name used or declared in the interface section is the most likely explanation.
However, unlike previous answers, since the problem only occurs in D2010 and not D7 then I would suspect the ExceptionHandler parameter of type TExceptionHandler, since D2010 includes a type with this name declared in ToolsAPI\IStreams.
You could qualify the name in the implementation section:
Where "MyUnit" is the name of the unit containing the "real" TExceptionHandler that you wish to use.
Or, you could alias the type in the interface section and change your parameter lists to consistently use the aliased type in both interface and implementation of this unit: