
06.12.2013, 23:51
|
Прохожий
|
|
Регистрация: 06.12.2013
Сообщения: 1
Версия Delphi: Delphi 7
Репутация: 10
|
|
Массив класса круг
Добрый вечер.Хотел спросить кое что про массив Tpoint.Есть классы Круг и Квадрат.Но пока описан только круг.при выборе в круга в radiogroup и нажатии мыши,должны создаваться круги...и заноситься в массив Tpoint координаты X и Y....но когда я пытаюсь создать 2 круг,вылетает с ошибкой.Может кто нибудь подсказать в чём ошибка?
P.S. сразу хочу сказать,что делфи только начали изучать,и уже дали такое вот задание
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
lst1: TListBox;
pnl1: TPanel;
rg1: TRadioGroup;
clrbx1: TColorBox;
clrbx2: TColorBox;
lbl1: TLabel;
lbl2: TLabel;
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
Tpoint=class
x1,y1:integer;
colorbrush:TColor;
end;
Tcircle=class(Tpoint)
colorpen:TColor;
r:Real;
constructor CreateCr(newx1,newy1:integer;newcolorbrush,newcolorpen:TColor);
end;
TSquare=class(Tcircle)
ang:Real;
end;
var
Form1: TForm1;
fig:array[1..200] of Tpoint;
i:integer=0;
implementation
{$R *.dfm}
{ Tcircle }
constructor Tcircle.CreateCr(newx1, newy1: integer; newcolorbrush,
newcolorpen: TColor);
begin
x1:=newx1;
y1:=newy1;
colorbrush:=newcolorbrush;
colorpen:=newcolorpen;
Form1.Canvas.Brush.color:=colorbrush;
form1.canvas.Pen.color:=colorpen;
form1.Canvas.Ellipse(x1,y1,x1+40,y1+40);
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if(rg1.ItemIndex=0)and(Button=mbleft)then begin
Tcircle.CreateCr(X,Y,clrbx1.Selected,clrbx2.Selected);
lst1.Items.Add('Круг');
fig[i].x1:=X;
fig[i].y1:=Y;
i:=i+1;
end;
end;
end.
|