Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Laboratornye_OOP.doc
Скачиваний:
17
Добавлен:
11.03.2015
Размер:
1.04 Mб
Скачать
  1. Модуль Point.

Unit Point;

interface

uses

GraphObj, Graphics, Grids, SysUtils;

type

{ объект - Точка, потомок абстрактного класса }

TPoint = class(TGraphObj)

// объявление перекрытых родительских методов

constructor Create(ACanvas: TCanvas; AName: string; AX, AY: Integer;

AColor: TColor; AVisible: Boolean); override;

procedure Draw(AColor: TColor); override;

procedure Move(dX, dY: Integer); override;

procedure DrawGrid(AStringGrid: TStringGrid); override;

end;

implementation

constructor TPoint.Create(ACanvas: TCanvas; AName: string; AX, AY: Integer;

AColor: TColor; AVisible: Boolean);

begin

inherited Create(ACanvas, AName, AX, AY, AColor, AVisible);;

FClassName := 'TPoint';

end;

procedure TPoint.Draw(AColor: TColor);

begin

FCanvas.Pixels[X, Y] := AColor

end;

procedure TPoint.Move(dX, dY: Integer);

begin

Hide;

inc(FX, dX);

inc(FY, dY);

Show;

end;

procedure TPoint.DrawGrid(AStringGrid: TStringGrid);

begin

inherited DrawGrid(AStringGrid);

with AStringGrid do

begin

Cells[0, 4] := 'X';

Cells[1, 4] := IntToStr(FX);

Cells[0, 5] := 'Y';

Cells[1, 5] := IntToStr(FY);

end

end;

end.

  1. Модуль Circle.

unit Circle;

interface

uses

Point, Graphics, Grids, SysUtils;

type

TCircle = class(TPoint)

private

FR: Integer;

public

constructor Create(ACanvas: TCanvas; AName: string; AX, AY, AR: Integer; AColor: TColor);

procedure Draw(AColor: TColor); override;

procedure DrawGrid(AStringGrid: TStringGrid); override;

procedure EditGrid(AStringGrid: TStringGrid; ARow: Integer); override;

property R: Integer read FR write FR nodefault;

end;

implementation

constructor TCircle.Create(ACanvas: TCanvas; AName: string; AX, AY, AR: Integer; AColor: TColor);

begin

inherited Create(ACanvas, AName, AX, AY, AColor);;

FClassName := 'TCircle';

FR := AR;

end;

procedure TCircle.Draw(AColor: TColor);

begin

PCanvas.Pen.Color := AColor;

PCanvas.Ellipse(X - FR, Y + FR, X + FR, Y - FR)

end;

procedure TCircle.DrawGrid(AStringGrid: TStringGrid);

begin

inherited DrawGrid(AStringGrid);

with AStringGrid do

begin

Cells[0, 6] := 'R';

Cells[1, 6] := IntToStr(FR);

end

end;

procedure TCircle.EditGrid(AStringGrid: TStringGrid; ARow: Integer);

begin

inherited EditGrid(AStringGrid, ARow);

if ARow = 6 then FR := StrToInt(AStringGrid.Cells[1, 6]);

end;

end.

  1. Модуль Rect.

unit Rect;

interface

uses

Square, Graphics, Grids, SysUtils;

type

// объект - Прямоугольник, наследуется от Квадрата

TRect = class(TSquare)

protected

FHeight: Integer; // высота прямоугольника

(длина Width наследуется от родителя)

public

// объявление перекрытых родительских методов

constructor Create(ACanvas: TCanvas; AName: string; AX, AY, AWidth, AHeight: Integer;AColor: TColor; AVisible: Boolean);

procedure Draw(AColor: TColor); override;

procedure DrawGrid(AStringGrid: TStringGrid); override;

procedure EditGrid(AStringGrid: TStringGrid; ARow: Integer); override;

property Height: Integer read FHeight write FHeight;

end;

implementation

constructor TRect.Create(ACanvas: TCanvas; AName: string; AX, AY, AWidth,

AHeight: Integer;AColor: TColor; AVisible: Boolean);

begin

inherited Create(ACanvas, AName, AX, AY, AWidth, AColor, AVisible);

FClassName := 'TRect';

FHeight := AHeight;

end;

procedure TRect.Draw(AColor: TColor);

begin

FCanvas.Pen.Color := AColor;

FCanvas.Rectangle(X, Y, X + FWidth, Y + FHeight)

end;

procedure TRect.DrawGrid(AStringGrid: TStringGrid);

begin

inherited DrawGrid(AStringGrid);

with AStringGrid do

begin

Cells[0, 7] := 'Height';

Cells[1, 7] := IntToStr(FHeight);

end

end;

procedure TRect.EditGrid(AStringGrid: TStringGrid; ARow: Integer);

begin

inherited EditGrid(AStringGrid, ARow);

if ARow = 7 then FHeight := StrToInt(AStringGrid.Cells[1, 7]);

end;

end.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]