unit InterfaceSpaszUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
IMyIF =
Interface(IInterface)
function GetLength(i: Integer): Integer;
end;
TMyExample =
class(TInterfacedObject, IMyIF)
private
FEinFeld:
array of array of Integer;
public
constructor Create();
overload;
function GetLength(i: Integer): Integer;
end;
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
MyExample: TMyExample;
function GetWert(bsp: IMyIF):
String;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TMyExample }
constructor TMyExample.Create;
var
i: Integer;
begin
inherited Create;
SetLength(FEinFeld, 2);
for i := 0
to Length(FEinFeld) - 1
do
SetLength(FEinFeld[i], i);
end;
function TMyExample.GetLength(i: Integer): Integer;
begin
Result := Length(FEinFeld[i]);
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
MyExample := TMyExample.Create;
end;
function TForm1.GetWert(bsp: IMyIF):
String;
begin
Result := IntToStr(bsp.GetLength(1));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(GetWert(MyExample));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;
end.