Registriert seit: 7. Apr 2003
567 Beiträge
Delphi 2006 Enterprise
|
Re: Interface, Einsteigerproblem?
24. Mär 2004, 06:12
Also ist es so richtig?
Delphi-Quellcode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
ITest1 = interface
[' {BC490D6F-306F-4FC5-AF6A-D76B39658B9F}']
procedure Test1;
end;
ITest2 = interface
[' {BDCB2821-FC57-4729-A1C0-9CEF3A28F72A}']
procedure Test2;
end;
TBaseClass = class(TInterfacedObject, ITest1)
public
procedure Test1; virtual;
end;
TTestClass = class(TBaseClass, ITest2)
public
procedure Test2;
procedure Test1; override;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TTestClass }
procedure TTestClass.Test1;
begin
inherited;
ShowMessage(' TTestClass.Test1;');
end;
procedure TTestClass.Test2;
begin
ShowMessage(' TTestClass.Test2;');
end;
{ TBaseClass }
procedure TBaseClass.Test1;
begin
ShowMessage(' TBaseClass.Test1;');
end;
procedure TForm1.Button1Click(Sender: TObject);
var aClass: TBaseClass;
aInterface1: ITest1;
aInterface2: ITest2;
begin
aClass := TTestClass.Create;
if aClass.QueryInterface(StringToGuid(' {BDCB2821-FC57-4729-A1C0-9CEF3A28F72A}'),aInterface2) = 0
then aInterface2.Test2;
if aClass.QueryInterface(StringToGuid(' {BC490D6F-306F-4FC5-AF6A-D76B39658B9F}'),aInterface1) = 0
then aInterface1.Test1;
end;
end.
Schöne Grüße,
Mario Noack
|
|
Zitat
|