Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading TThread中的继承问题,don';t在D2010中的工作方式似乎与D7相同_Multithreading_Delphi_Delphi 2010 - Fatal编程技术网

Multithreading TThread中的继承问题,don';t在D2010中的工作方式似乎与D7相同

Multithreading TThread中的继承问题,don';t在D2010中的工作方式似乎与D7相同,multithreading,delphi,delphi-2010,Multithreading,Delphi,Delphi 2010,在我的应用程序中,我有两个线程对象(Outer和Sash),它们继承自TThread类型的基本线程对象(FrameObject)。这一切在D7中运行良好。该应用程序需要扩展,我借此机会将其移动到D2010-但是,当我尝试编译Delphi时,会抱怨FrameObject创建方法声明与以前的声明不同 类类型和构造函数如下所示 TFrameObject = class(TThread) constructor TFrameObject.Create(BuildType: TBuildType; On

在我的应用程序中,我有两个线程对象(Outer和Sash),它们继承自TThread类型的基本线程对象(FrameObject)。这一切在D7中运行良好。该应用程序需要扩展,我借此机会将其移动到D2010-但是,当我尝试编译Delphi时,会抱怨FrameObject创建方法声明与以前的声明不同

类类型和构造函数如下所示

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中都可以正常工作(也许它不应该!)-那么我哪里出错了?

检查在多个单元中声明的类型,其中一个在接口中使用,另一个在实现部分中使用,例如,
TFrameObject
声明中的
TBuildType
(在接口部分)将解析为
UnitA.TBuildType
并实现为
UnitB.TBuildType

我猜想这里发生的事情是,实现部分中的
uses
子句正在声明一个
TBuildType
TBatchNotify
TNotifyTermination
与声明构造函数的接口部分中使用的不同


快速检查的方法是在
TFrameObject的实现中完全限定这些类型。创建

根据其他答案,最有可能的解释是,在实现部分使用的单元中新引入一个类型,隐藏在接口部分中使用或声明的同名类型

但是,与前面的答案不同,由于问题只发生在D2010中,而不是D7中,因此我怀疑ExceptionHandler参数的类型为TExceptionHandler,因为D2010包含一个在ToolsAPI\IStreams中声明了此名称的类型

您可以在“实现”部分中限定名称:

  TFrameObject.Create(... ExceptionHandler: MyUnit.TExpectionHandler)
其中“MyUnit”是包含您希望使用的“真实”TExceptionHandler的单元的名称

或者,您可以在“接口”部分中为该类型添加别名,并更改参数列表,以便在该单元的接口和实现中一致使用别名类型:

  interface

   type
     TFrameExceptionHandler = TExceptionHandler;

     TFrameObject = class...
       ...
       constructor Create(... ExceptionHandler: TFrameExceptionHandler);
     end;


  implementation

     constructor TFrameObject.Create(... ExceptionHandler: TFrameExceptionHandler);

有那么一刻,我以为这将是解决办法——但不幸的是,不是!(虽然我已经按照建议重命名了TExceptionHandler)。问题似乎出在TFrameObject(?)的Create方法中,因为这是Outer和Sash对象的基类,我看不出发生了什么-除非它抱怨TFrame的Create方法与底层TThread的Create方法不同@paul只需按照我的建议,完全限定构造函数参数的类型。并在您发表评论时使用@david,以便我收到评论通知。同时检查两个版本中的库路径顺序是否相同-这可能有助于您找到有问题的单元。针对这个问题的一个强力检查是重命名演示应用程序中的类。如果“TFrameObjectTest”仍然存在问题,那么您知道这一切都发生在您正在查看的单元中。