关于过程参数的调用(100分)

  • 主题发起人 主题发起人 terry_zhou82
  • 开始时间 开始时间
T

terry_zhou82

Unregistered / Unconfirmed
GUEST, unregistred user!
过程代码如下:
procedure change(var x:Tcomponent);
begin
form1.repaint;
form1.Canvas.pen.color:=clblue;
form1.Canvas.pen.width:=3;
form1.Canvas.polyline([point(speedbutton1.left,speedbutton1.top),
point(speedbutton1.left+speedbutton1.width,speedbutton1.top),
point(speedbutton1.left+speedbutton1.width,speedbutton1.top+speedbutton1.height),
point(speedbutton1.left,speedbutton1.top+speedbutton1.height),
point(speedbutton1.left,speedbutton1.top)]);
end;

我想把上面的这段改写成过程,是不是把里面的SPEEDBUTTON1改成X?

如果调用的话,我用
Procedure button1.onclick(sender:Tobject);
begin
change(button2);//如果我要用BUTTON2也实现这个功能
end;

对不对,好像老是报错啊,望各位大哥多多指点小弟,谢谢!
 
Tcomponent没有 left属性,你要换成x,类型可以定义成TControl
或则用 (x as Tspeedbutton).left
 
procedure TForm1.change(var x: TButton);
begin
form1.repaint;
form1.Canvas.pen.color:=clblue;
form1.Canvas.pen.width:=3;
with x do begin
form1.Canvas.polyline([point(left,top),point(left+width,top),
point(left+width,top+height),point(left,top+height),
point(left,top)]);
end;
end;
 
procedure Change(obj: TObject);
var Btn: TButton;
begin
Btn := TButton(obj);
with Btn do begin
Form1.Canvas.PolyLine([point(left,top),point(left+width,top),
point(left+width,top+height),point(left,top+height),
point(left,top)]);
end;
end;
 
后退
顶部