📄 unitfile.pas
字号:
unit Unitfile;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
IInterface1 = interface
['{B443045D-A019-48B6-B524-6B9A64B3BACB}']
function GetInfo:String;
end;
TInterface1Impl1 = class(TInterfacedObject,IInterface1)
function GetInfo:String;
end;
TInterface1Impl2 = class(TInterface1Impl1,IInterface1)
function GetInfo:String;
end;
IInterface2 = interface
['{0D392C0E-55EE-4489-9A79-AFB6B680F597}']
function GetInfo:String;
function MyGetInfo:String;
end;
TInterface2Impl = class(TInterfacedObject,IInterface1,IInterface2)
public
function IInterface2.GetInfo = MyGetInfo;
function GetInfo:String;
function MyGetInfo:String;
end;
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TInterface1Impl1 }
function TInterface1Impl1.GetInfo: String;
begin
Result := '调用的是TInterface1Impl1.GetInfo!';
end;
{ TInterface1Impl2 }
function TInterface1Impl2.GetInfo: String;
begin
Result := '调用的是TInterface1Impl2.GetInfo!';
end;
{ TInterface2Impl }
function TInterface2Impl.GetInfo: String;
begin
Result := '调用的是IInterface1.GetInfo!';
end;
function TInterface2Impl.MyGetInfo: String;
begin
Result := '调用的是IInterface2.GetInfo!';
end;
procedure TForm1.Button1Click(Sender: TObject);
var
MyInterface:IInterface1;
begin
MyInterface := TInterface1Impl1.Create;
Memo1.Lines.Append(MyInterface.GetInfo);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
MyInterface:IInterface1;
begin
MyInterface := TInterface1Impl2.Create;
Memo1.Lines.Append(MyInterface.GetInfo);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
MyInterface:IInterface1;
begin
MyInterface := TInterface2Impl.Create;
Memo1.Lines.Append(MyInterface.GetInfo);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
MyInterface:IInterface2;
begin
MyInterface := TInterface2Impl.Create;
Memo1.Lines.Append(MyInterface.MyGetInfo);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -