16,748
社区成员
发帖
与我相关
我的任务
分享
unit Unit2;
interface
uses
Windows;
type
IBase = interface
procedure a;
end;
IMyTest = interface(IBase)
procedure b;
end;
tbase = class(TInterfacedObject, ibase)
procedure a;
end;
tmytest = class(tbase, imytest)
procedure b;
end;
function CreateMytest: IBase;
implementation
{ tbase }
procedure tbase.a;
begin
end;
{ tmytest }
procedure tmytest.b;
begin
MessageBox(0, 'test', 'test', MB_OK);
end;
function CreateMytest: IBase;
begin
Result := tmytest.create;
end;
end.
// 測試:
procedure TForm2.Button1Click(Sender: TObject);
var
a : IMyTest;
begin
a := CreateMytest;
IMyTest(A).b;
end;
[/Quote]
unit Unit3;
interface
uses
Windows;
type
IBase = interface
procedure a;
end;
IMyTest = interface(IBase)
procedure b;
end;
Tbase = class(TInterfacedObject, ibase)
procedure a;
end;
Tmytest = class(tbase, imytest)
procedure b;
end;
function CreateMytest: imytest;
implementation
{ tbase }
procedure tbase.a;
begin
end;
{ tmytest }
procedure tmytest.b;
begin
MessageBox(0, 'test', 'test', MB_OK);
end;
function CreateMytest: imytest;
begin
Result := Tmytest.create;
end;
end.
// 測試:
procedure TForm2.Button1Click(Sender: TObject);
var
a : IMyTest;
begin
a := CreateMytest;
IMyTest(A).b;
end;
var a: IBase;
begin
a:=tbase.Create;
//或者a:=tmytest.Create;
tmytest(a).b;
end;