In a Form I have a Paintbox with property Align = alClient and a Button .
I need to draw a Canvas object within Paintbox in the Button OnCLick event . This is the Canvas object to create:
const IconSize:Integer = 10
type
Icon = Class
public
posX, posY:Integer;
constructor Create(X,Y:Integer);
destructor Destroy;
procedure SetX(AValue: Integer);
procedure SetY(AValue: Integer);
published
property LocationX : Integer read posX write SetX;
property LocationY : Integer read posY write SetY;
end;
var CanvasIcon: Icon;
This is the constructor method of the object:
constructor Icon.Create(X, Y: Integer);
var Bitmap:TBitmap;
begin
Bitmap:=TBitmap.Create;
try
Bitmap.Height := IconSize;
Bitmap.Width := IconSize;
Bitmap.Canvas.Pen.Color := clBlack;
Bitmap.Canvas.Rectangle(Round(X-(IconSize/2)), Round(Y-(IconSize/2)),
Round(X+(IconSize/2)), Round(Y+(IconSize/2)));
PaintBox.Canvas.Draw(0, 0, Bitmap);
finally
Bitmap.Free;
end;
end;
And this is the OnClick event of the Button :
procedure TFormPaintBox.Button1Click(Sender: TObject);
begin
CanvasIcon:=Icon.Create(10,10);
end;
However, Lazarus displays the following error message:
src / unitpaintbox.pas (121,33) Error: Wrong number of parameters specified for call to "Create"
But the constructor receives two parameters, exactly as it was specified in the Button event of Button . How can I solve this problem?