How to create a Canvas object in Lazarus and add it to a Paintbox?

Asked

Viewed 286 times

0

In a Form have a Paintbox property Align = alClient and a Button.

I need to draw an object of the type Canvas within the Paintbox at the event Onclick of Button. This is the object of type Canvas which should be created:

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 method constructor 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 event Onclick of 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 specified in the event onClick of Button. How can I solve this problem?

  • Problem solved as follows: editing the Icon for CustomIcon, and removing the entries of constructor Create;

1 answer

-1

  • Apart from the fact that the problem has already been solved by the questioner himself, his answer does not provide a solution of adequate quality. Just including a link doesn’t help. It’s the same as using the following answer for everything: "Google Search you find", agree?

  • I’m sorry, I just tried to contribute. I hope to improve the next.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.