pascalabcnet/InstallerSamples/!MainFeatures/06_Classes/Interf.pas
2025-10-12 22:21:43 +03:00

43 lines
863 B
ObjectPascal

// Иллюстрация использования интерфейсов
type
IShape = interface
procedure Draw;
property X: integer read;
property Y: integer read;
end;
ICloneable = interface
function Clone: Object;
end;
Point = class(IShape,ICloneable)
private
xx,yy: integer;
public
constructor Create(x,y: integer);
begin
xx := x; yy := y;
end;
procedure Draw; begin end;
property X: integer read xx;
property Y: integer read yy;
function Clone: Object;
begin
Result := new Point(xx,yy);
end;
end;
begin
var p: Point := new Point(2,3);
var ish: IShape := p;
var icl: ICloneable := p;
Println(ish.X,ish.Y);
var p1: Point := Point(icl.Clone);
p := nil;
Println(p1.X,p1.Y);
Println(ish is Point);
Println(ish is ICloneable); // Cross cast!
end.