请教一个关于Delphi中接口使用的问题!(100分)

  • 主题发起人 主题发起人 贪杯的灵魂Z
  • 开始时间 开始时间

贪杯的灵魂Z

Unregistered / Unconfirmed
GUEST, unregistred user!
以下是我的代码
代码:
  ISubject = interface (IInterface)
    ['{D3292358-E800-4741-B77A-83605F112591}']
    procedure DoSomething;
  end;

  TActGraphList = class (TObjectList, ISubject)
  public
    constructor Create;
    procedure DoSomething;
  end;
当编译时,出现以下错误信息
[Error] Graph.pas(482): Undeclared identifier: 'QueryInterface'
[Error] Graph.pas(482): Undeclared identifier: '_AddRef'
[Error] Graph.pas(482): Undeclared identifier: '_Release'
我尝试着通过查看帮助解决次问题,但未能如愿。
恳请热心的网友们“拔刀相助”!
再次,偶先谢过了!
 
接口要实现的:改成如下:
TActGraphList = class (TObjectList, ISubject)
public
constructor Create;
procedure DoSomething;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;

end;
 
ISubject = interface (IInterface)
['{D3292358-E800-4741-B77A-83605F112591}']
procedure DoSomething;
end;

TActGraphList = class (TObjectList, ISubject)
public
constructor Create;
procedure DoSomething;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
end;
 
谢谢两位网友的热心建议。
你们的提议的方法我也试过了,但是又会出现以下错误信息
[Error] Graph.pas(476): Declaration of 'QueryInterface' differs from declaration in interface 'ISubject'
[Error] Graph.pas(476): Declaration of '_AddRef' differs from declaration in interface 'ISubject'
[Error] Graph.pas(476): Declaration of '_Release' differs from declaration in interface 'ISubject'
呵呵,what can i do?!
 
我试了一下没有问题:
unit Unit2;

interface
uses windows,Contnrs;
type
ISubject = interface (IInterface)
['{D3292358-E800-4741-B77A-83605F112591}']
procedure DoSomething;
end;

TActGraphList = class (TObjectList, ISubject)
public
constructor Create;
procedure DoSomething;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;

end;

implementation

{ TActGraphList }

constructor TActGraphList.Create;
begin
sleep(1);
end;

procedure TActGraphList.DoSomething;
begin
sleep(1);

end;

function TActGraphList._AddRef: Integer;
begin
result:=1;

end;

function TActGraphList._Release: Integer;
begin
result:=2;
end;

function TActGraphList.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
result:=0;
end;

end.
 
后退
顶部