Delphi 介面託管實現

來源:互聯網
上載者:User

標籤:

 1 unit Unit1; 2  3 interface 4  5 uses 6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7   Dialogs, StdCtrls; 8  9 type10   TForm1 = class(TForm)11     Button1: TButton;12     procedure Button1Click(Sender: TObject);13   private14     { Private declarations }15   public16     { Public declarations }17   end;18 19   IMyInterface = interface(IUnknown)20    procedure ShowString(s: string);21   end;22 23   TMyClass = class(TInterfacedObject, IMyInterface)24   public25     procedure ShowString(s: string);26   end;27 28   TSecondClass = class(TInterfacedObject, IMyInterface)29   protected30     myInterface: IMyInterface;31   protected32     property my: IMyInterface read myInterface implements IMyInterface;33   public34     constructor Create(AOwner: TObject); overload;35   end;36 37 38 var39   Form1: TForm1;40 41 implementation42 43 {$R *.dfm}44 45 procedure TForm1.Button1Click(Sender: TObject);46 var47   myclass: TMyClass;48   mySecondclass: TSecondClass;49 begin50   myclass := TMyClass.Create;51   mySecondclass := TSecondClass.Create(nil);52   myclass.ShowString(‘sss‘);53   mySecondclass.my.ShowString(‘aaa‘);54   myclass.Free;55   mySecondclass.Free;56 end;57 58 { TMyClass }59 60 procedure TMyClass.ShowString(s: string);61 begin62   ShowMessage(s);63 end;64 65 { TSecondClass }66 67 constructor TSecondClass.Create(AOwner: TObject);68 begin69   myInterface := TMyClass.Create;70 end;71 72 end.

 

Delphi 介面託管實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.