在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
"接口" 的概念和 "类" 特别是 "抽象类" 近似, Delphi 之初并没有接口, 后来(Delphi 3)为了支持 COM 引入了接口, 再后来发展成为 Delphi 重要的语言特性.
Delphi 的接口(2) - 第一个例子unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); end; IMyInterface1 = interface function Func1: Integer; function Func2: Integer; end; IMyInterface2 = interface procedure Proc1; procedure Proc2; end; TMyClass1 = class(TInterfacedObject, IMyInterface1, IMyInterface2) public procedure Proc1; procedure Proc2; function Func1: Integer; function Func2: Integer; end; var Form1: TForm1; implementation {$R *.dfm} { TMyClass1 } function TMyClass1.Func1: Integer; begin ShowMessage('IMyInterface1.Func1'); Result := 0; end; function TMyClass1.Func2: Integer; begin ShowMessage('IMyInterface1.Func2'); Result := 0; end; procedure TMyClass1.Proc1; begin ShowMessage('IMyInterface2.Proc1'); end; procedure TMyClass1.Proc2; begin ShowMessage('IMyInterface2.Proc2'); end; procedure TForm1.Button1Click(Sender: TObject); var c: TMyClass1; begin c := TMyClass1.Create; c.Func1; c.Func2; c.Pro |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论