Задание по Delphi создание фигур разного цвета при нажатии на 2 кнопки(2 цвета к каждой фигуре). Ниже приведу модуль. В конце создаётся ворма но при нажатии на кнопки не создаются фигуры.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm2 = class(TForm)
btnRedCircle: TBitBtn;
btnWhiteSquare: TBitBtn;
btnBlackSquare: TBitBtn;
btnYellowEllipse: TBitBtn;
btnGreenEllipse: TBitBtn;
BitBtn7: TBitBtn;
btnBlueCircle: TBitBtn;
procedure AllBtnClick(Sender: TObject);
end;
ArrayColor = array[1..6] of TColor;
TDrawArea = class(TPersistent)
private
x1,y1,x2,y2:integer;
FArrayBrushColor: ArrayColor;
FPenColor: TColor;
function GetBrushColor(pIndex:integer): TColor;
public
constructor InitColor;
constructor InitXY(NewX1,NewY1,NewX2,NewY2:integer);
property PPenCOlor: TColor read FpenColor
write FpenColor Default clBlack;
property PBrushColor[pIndex:integer]: TColor read GetBrushColor;
procedure DrawFig;virtual;abstract;
procedure DrawIt;
end;
TSquare = class (TDrawArea)
procedure DrawFig;override;
end;
TEllipse = class (TDrawArea)
procedure DrawFig;override;
end;
TCircle = class (TDrawArea)
procedure DrawFig;override;
end;
var
Form2: TForm2;
MySquare:TSquare;
MyEllipse:TEllipse;
MyCircle:TCircle;
implementation
{$R *.dfm}
Constructor TDrawArea.InitColor;
begin
FArrayBrushColor[1]:=clRed;
FArrayBrushColor[2]:=clBlue;
FArrayBrushColor[3]:=clBlack;
FArrayBrushColor[4]:=clWhite;
FArrayBrushColor[5]:=clYellow;
FArrayBrushColor[6]:=clGreen;
End;
Constructor TDrawArea.InitXY(NewX1,NewY1,NewX2,NewY2:integer);
begin
x1:=NewX1;
y1:=NewY1;
x2:=NewX2;
y2:=NewY2;
end;
Function TDrawArea.GetBrushColor(pIndex:integer):TColor;
begin
result:=-1;
if pIndex in [1..6] then result:=FArrayBrushColor[pIndex];
end;
Procedure TDrawArea.DrawIt;
begin
DrawFig;
end;
procedure TSquare.DrawFig;
begin
Form2.Canvas.Rectangle(x1,y1,x2,y2);
end;
procedure TCircle.DrawFig;
begin
Form2.Canvas.Ellipse(x1-x2,y1-x2,x1+x2,y1+x2);
end;
procedure TEllipse.DrawFig;
begin
Form2.Canvas.Ellipse(x1,y1,x2,y2);
end;
procedure TForm2.AllBtnClick(Sender: TObject);
begin
if (Sender as TBitBtn=btnRedCircle) or
(Sender as TBitBtn=btnRedCircle) then begin
if not assigned(MyCircle) then begin
MyCircle:=TCircle.Create;
MyCircle.InitColor;
MyCircle.InitXY(50,50,40,0);
Form2.Canvas.Pen.Color:=MyCircle.PPencolor;
end;
if Sender as TBitBtn=btnRedCircle then begin;
Form2.Canvas.Brush.Color:=MyCircle.PBrushColor[1];
MyCircle.DrawIt;
end;
if Sender as TBitBtn=btnBlueCircle then begin;
Form2.Canvas.Brush.Color:=MyCircle.PBrushColor[2];
MyCircle.DrawIt;
end;
end;
if (Sender as TBitBtn=btnBlackSquare) or
(Sender as TBitBtn=btnWhiteSquare) then begin
if not assigned(MySquare) then begin
MySquare:=TSquare.Create;
MySquare.InitColor;
MySquare.InitXY(110,10,190,90);
Form2.Canvas.Pen.Color:=MySquare.PPencolor;
end;
if Sender as TBitBtn=btnBlackSquare then begin;
Form2.Canvas.Brush.Color:=MySquare.PBrushColor[3];
MySquare.DrawIt;
end;
if Sender as TBitBtn=btnWhiteSquare then begin;
Form2.Canvas.Brush.Color:=MySquare.PBrushColor[4];
MySquare.DrawIt;
end;
if (Sender as TBitBtn=btnYellowEllipse) or
(Sender as TBitBtn=btnGreenEllipse) then begin
if not assigned(MyEllipse) then begin
MyEllipse:=TEllipse.Create;
MyEllipse.InitColor;
MyEllipse.InitXY(220,10,280,90);
Form2.Canvas.Pen.Color:=MyEllipse.PPencolor;
end;
if Sender as TBitBtn=btnYellowEllipse then begin;
Form2.Canvas.Brush.Color:=MyEllipse.PBrushColor[5];
MyEllipse.DrawIt;
end;
if Sender as TBitBtn=btnGreenEllipse then begin;
Form2.Canvas.Brush.Color:=MyEllipse.PBrushColor[6];
MySquare.DrawIt;
end;
end;
end;
end;
end.