在我的应用程序中,我有两个线程对象(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 中都能正常工作(也许不应该!) - 那么我哪里出错了?
最佳答案
检查在多个单元中声明的类型,其中一个在接口(interface)中使用,另一个在实现部分中使用,例如 TFrameObject
声明中的 TBuildType
(在接口(interface)部分)将解析为 UnitA.TBuildType
并实现为 UnitB.TBuildType
。
关于multithreading - TThread 中的继承问题,在 D2010 中的工作方式似乎与 D7 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4795563/