type
IIF = interface(IUnknown)
['{E351FAF7-1A12-4164-8866-7ED2D8599174}']
procedure mm;
end; TIF = class(TObject, IIF)
protected
FRefCount: Integer;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
procedure mm;
public
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
class function NewInstance: TObject; override;
property RefCount: Integer read FRefCount;
end;
...
...
procedure TForm1.Button1Click(Sender: TObject);
var
ti: IIF;
t: tif;
begin
t := tif.Create;
ti := t as IIF; //为什么不行 [Error] Unit1.pas(51): Operator not applicable to this ..
IIF = interface(IUnknown)
['{E351FAF7-1A12-4164-8866-7ED2D8599174}']
procedure mm;
end; TIF = class(TObject, IIF)
protected
FRefCount: Integer;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
procedure mm;
public
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
class function NewInstance: TObject; override;
property RefCount: Integer read FRefCount;
end;
...
...
procedure TForm1.Button1Click(Sender: TObject);
var
ti: IIF;
t: tif;
begin
t := tif.Create;
ti := t as IIF; //为什么不行 [Error] Unit1.pas(51): Operator not applicable to this ..
解决方案 »
- tstrings
- savedialog自动保存问题。
- 一个特殊异常的问题
- COM调用改TCP/IP问题,请高手赐教
- 如何使用GetVolumeInformation?(在线等待)
- 哪有delphi插件for powerdesigner
- 用idpop3控件无法接收MIME编码的附件,请问如何解决?分不是问题!!!!!!!
- 如何在win2000下屏蔽ctrl-alt-del或者让任务管理器按钮失效
- 一个奇怪的问题?我是没有头绪,有谁能解?
- 透明窗口再次设置的问题?
- 连接SQL SERVER,把LoginPrompt设置为了False,提示说用户sa登录失败!
- 我想开个DELPHI程序员培训班,请大家帮我想一些骟动性的广告词
TIF = class(TObject, IIF, IInterface)When you use the as operator for dynamic binding on an interface, you should be aware of the following requirements:
1)Explicitly declaring IInterface: Although all interfaces derive from IInterface, it is not sufficient, if you want to use the as operator, for a class to simply implement the methods of IInterface. This is true even if it also implements the interfaces it explicitly declares. The class must explicitly declare IInterface in its interface list.
2)Using an IID: Interfaces can use an identifier that is based on a GUID (globally unique identifier). GUIDs that are used to identify interfaces are referred to as interface identifiers (IIDs). If you are using the as operator with an interface, it must have an associated IID. To create a new GUID in your source code you can use the Ctrl+Shift+G editor shortcut key.
IIF = interface(IUnknown)
['{E351FAF7-1A12-4164-8866-7ED2D8599174}']
procedure mm;
end; TIF = class(TinterfacedObject, IIF)
protected
FRefCount: Integer;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
procedure mm;
public
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
class function NewInstance: TObject; override;
property RefCount: Integer read FRefCount;
end;
[Error] Unit2.pas(13): Undeclared identifier: 'IInterface'
因为我用delphi5 所以没有'IInterface'??to dinglinger(叮当)
I just want to know why my 不行..
TIF = class(TObject, IIF) ->
TIF = class(TObject, IIF, IUnknown)
你写错了吧 这样倒是可以 研究英文中
IUnknown = IInterface