如何在Lazarus上的Paintbox中创建Canvas对象?

时间:2015-03-26 18:49:09

标签: pascal lazarus

表单上,我使用属性 Align = alClient 按钮放置 Paintbox 。 我需要在按钮 OnClick 事件中的 PaintBox 中绘制 Canvas 类型的对象。

这是将要创建的 Canvas 对象:

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;

这是对象的构造函数方法:

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;   

这是按钮 OnClick 事件:

procedure TFormPaintBox.Button1Click(Sender: TObject);
begin
  CanvasIcon:=Icon.Create(10,10);
end;

然而,拉撒路显示以下信息:

  

src / unitpaintbox.pas(121,33)错误:为调用“创建”指定的参数数量错误

构造函数会收到两个参数,与按钮 onClick 事件中指定的参数完全相同。如何解决这个问题?

0 个答案:

没有答案