问题1:
定义一个接口TCommunication,该接口需要提供两个事件,事件是这样定义的
TCancelEvent = procedure(bCancel:Boolean) of object;
TErrorEvent = procedure(strErrDes:String) of object;
还需要一个构造函数和两个方法,定义如下
constructor Create(CommunicationType:Integer):String;
function ReadData():String;
function WriteData():Boolean
定义上面的接口,delphi下应该如何写?问题2:
现在我有两个类TCommunicationA,TCommunicationB需要实现上述的接口
delphi下应该如何写?各位能不能帮忙写个我可以在里面填写的框架,谢谢。
定义一个接口TCommunication,该接口需要提供两个事件,事件是这样定义的
TCancelEvent = procedure(bCancel:Boolean) of object;
TErrorEvent = procedure(strErrDes:String) of object;
还需要一个构造函数和两个方法,定义如下
constructor Create(CommunicationType:Integer):String;
function ReadData():String;
function WriteData():Boolean
定义上面的接口,delphi下应该如何写?问题2:
现在我有两个类TCommunicationA,TCommunicationB需要实现上述的接口
delphi下应该如何写?各位能不能帮忙写个我可以在里面填写的框架,谢谢。
TErrorEvent = procedure(strErrDes:String) of object; ICommunication = interface
Procedure SetCancelEvent(value: TCancelEvent);
function GetCancelEvent: TCancelEvent;
Procedure SetErrorEvent(value: TErrorEvent);
function GetErrorEvent: TErrorEvent;
function ReadData():String;
function WriteData():Boolean; Property OnCancel: TCancelEvent read GetCancelEvent write SetCancelEvent;
Property OnError: TErrorEvent read GetErrorEvent write SetErrorEvent;
end; TCommunicationA = Class(TInterfacedObject, ICommunication)
Procedure SetCancelEvent(value: TCancelEvent);
function GetCancelEvent: TCancelEvent;
Procedure SetErrorEvent(value: TErrorEvent);
function GetErrorEvent: TErrorEvent;
function ReadData():String;
function WriteData():Boolean; Property OnCancel: TCancelEvent read GetCancelEvent write SetCancelEvent;
Property OnError: TErrorEvent read GetErrorEvent write SetErrorEvent;
end;也可以不使用借口,直接将TCommunication定义成一个抽象类。然后从类下面继承
TCommunicationA = Class(TInterfacedObject, ICommunication)
private
FOnCancel: TCancelEvent;
FOnError: TErrorEvent;
public
Procedure SetCancelEvent(value: TCancelEvent);
function GetCancelEvent: TCancelEvent;
Procedure SetErrorEvent(value: TErrorEvent);
function GetErrorEvent: TErrorEvent;
function ReadData():String;
function WriteData():Boolean; Property OnCancel: TCancelEvent read GetCancelEvent write SetCancelEvent;
Property OnError: TErrorEvent read GetErrorEvent write SetErrorEvent;
end;