Delphi的处理原则是:
代码如下:
1.声明接口
type
IInter1=interface ['{769D95CA-90CE-41BA-A195-A6F43A30A3FC}']
function getname:string; procedure setname(sname:string);
end;
IInter2=interface ['{1CE978B4-F7AC-44B1-9EAD-5B8CCE1510A1}']
getname:string; function
setname(sname:string); procedure
end;
2.创建类
声明部分
type
TMyClass=class(TInterfacedobject,IInter1,IInter2)
private
FName:string;
public
{ DONE : 设定别名 }
function IInter1.getName=Inter1_getname;
function IInter2.getName=Inter2_getname;
procedure IInter1.setname=Inter1_setname;
procedure IInter2.setname=Inter2_setname;
{ DONE : 重新命名 }
function Inter1_getname:string;
function Inter2_getname:string;
procedure Inter1_setname(sname:string);
procedure Inter2_setname(sname:string);
{ DONE : 析构 }
destructor destroy;override;
end;
实现部分
{ TMyClass }
destructor TMyClass.destroy;
begin
MessageDlg('exit object',mtinformation,[mbok],0);
inherited;
end;
function TMyClass.Inter1_getname: string;
begin
MessageDlg('get inter1 name',mtinformation,[mbok],0);
Result:=FName;
end;
procedure TMyClass.Inter1_setname(sname: string);
begin
MessageDlg('set inter1 name',mtinformation,[mbok],0);
FName:=sname;
end;
function TMyClass.Inter2_getname: string;
begin
MessageDlg('get inter2 name',mtinformation,[mbok],0);
Result:=FName;
end;
procedure TMyClass.Inter2_setname(sname: string);
begin
MessageDlg('set inter2 name',mtinformation,[mbok],0);
FName:=sname;
end;
3.调用以上类中的函数:
procedure TForm1.Button1Click(Sender: TObject);
begin
myclass:=TMyClass.Create;
try
myclass.Inter1_setname('88');
ShowMessage(myclass.Inter2_getname);
finally
myclass.Free;
end;
end;