Delphi 接口托管实现
2015-07-31 17:37
387 查看
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; IMyInterface = interface(IUnknown) procedure ShowString(s: string); end; TMyClass = class(TInterfacedObject, IMyInterface) public procedure ShowString(s: string); end; TSecondClass = class(TInterfacedObject, IMyInterface) protected myInterface: IMyInterface; protected property my: IMyInterface read myInterface implements IMyInterface; public constructor Create(AOwner: TObject); overload; end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var myclass: TMyClass; mySecondclass: TSecondClass; begin myclass := TMyClass.Create; mySecondclass := TSecondClass.Create(nil); myclass.ShowString('sss'); mySecondclass.my.ShowString('aaa'); myclass.Free; mySecondclass.Free; end; { TMyClass } procedure TMyClass.ShowString(s: string); begin ShowMessage(s); end; { TSecondClass } constructor TSecondClass.Create(AOwner: TObject); begin myInterface := TMyClass.Create; end; end.
相关文章推荐
- DELPHI中自定义消息的发送和接收
- DELPHI 泛型
- *Delphi中ExtractFilePath、ParamStr以及更多文件/目录操作涉及的函数。附加对应的例子
- *Delphi的 Format格式化函数
- *Delphi的Trim函数
- Delphi对象和指向对像的指针
- Delphi7学习第七天
- *Delphi容器类之---Tlist,TStringlist,THashedStringlist的效率比较
- Delphi笔记-自定义组件
- delphi的日期和时间显示
- *Delphi的分配及释放---New/Dispose, GetMem/FreeMem及其它函数的区别与相同
- Delphi 7学习第六天-简单登陆界面的实现
- Delphi中双字节类型存储到整型变量的问题
- Delphi 7中ADDConnection 连接MySQL数据库
- Delphi2010/XE2下隐藏程序系统任务栏的图标
- DELPHI RES资源文件使用方法
- Delphi DateUtils时间单元
- Delphi 不管什么日期格式转换都不会错了
- delphi 判断调试状态
- Delphi7学习第五天