续承了tbutton部件之后如何在onclick事件中添加自己的代码?(50分)

  • 主题发起人 主题发起人 xuyingfeng
  • 开始时间 开始时间
X

xuyingfeng

Unregistered / Unconfirmed
GUEST, unregistred user!
请教大侠:
续承了tbutton部件之后如何在onclick事件中添加自己的代码?比如说要添加
inputquery('更改capion名称','',Fcaption);之类的
thank very!!!!!!!!!!!!!!!!!!!!!!much;
 
查看一下TButton的源码就明白
 
override就好了呀。直接在UNIT里写好就行了,要不可以这样,先写一过程,注意其参数
和返回值要和ONCLICK的完全一样,然后让ONCLICK:=该过程就可以了。
 
sorry 各位大侠,我说的是在制作一个新的控件时,在新控件里的onclick事件里怎么添加自己的代码
(最好有原码)!!!!!!!
请看以下代码毛病在哪里?为什么点了按钮之后没有反应呢?
unit button2;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
tbutton2 = class(tbutton)
private
Fonclick:tnotifyevent;
procedure Fmyonclick(Sender: TObject);
{ Private declarations }
protected
{ Protected declarations }
public
constructor create(aowner:tcomponent);override;
{ Public declarations }
published
property onclick:tnotifyevent read fonclick write fonclick;
{ Published declarations }
end;

procedure Register;

implementation
constructor tbutton2.create(aowner:tcomponent);
begin
inherited;
onclick:=fmyonclick;
end;
procedure tbutton2.fmyonclick(Sender: TObject);
begin
if assigned(fonclick) then begin fonclick(self);end;
application.messagebox('','',mb_ok);//自己的代码
end;

procedure Register;
begin
RegisterComponents('Samples', [tbutton2]);
end;

end.
 
inherited;
onclick:=fmyonclick;
你应该重载Tbutton.Onclick.
 
好像不是你这样写的吧?
但我现在手上没有现成的原吗,我也写不出来(我一向用以前用过的一段代码作莫版来改的)
你仔细看看delphi空间的原吗,请严格按照它的那种格式来写
我记得要声明一个过程并用message标注吧。
 
zhang w.的答案难道不对吗?
 
你的声明错了。只需在
type
...
protected
{ Protected declarations }
procedure paint;override;
procedure dblclick;override;
procedure click;override;
...
procedure tfznbox.click;
begin
...
end;

就可以了,以上已经经过验证。不要搞混,ONCLICK其实就是CLICK,你写错了。
 
我还是搞不定,照threego的方法作了,通不过,能不能给个完全代码~~!!!!!
一定重谢!!!!!!!!
 
应该这么写:
unit MyButton;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TMyButton = class(TButton)
private
{ Private declarations }
procedure MyClick(Sender:Tobject);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
published
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Liao', [TMyButton]);
end;

{ TMyButton }

constructor TMyButton.Create(AOwner: TComponent);
begin
inherited;
OnClick := MyClick;
end;

procedure TMyButton.MyClick(Sender: Tobject);
begin
ShowMessage('你明白否?');//自己的代码
end;

end.
 
type
Tfznbox = class(TPaintbox)
private
{ Private declarations }
....
protected
{ Protected declarations }
procedure paint;override;
procedure dblclick;override;
procedure click;override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer
); override;
procedure Mousemove(Shift: TShiftState;X, Y: Integer
); override;
procedure MouseUP(Button: TMouseButton; Shift: TShiftState; X, Y: Integer
); override;
public
{ Public declarations }
constructor create(AOwner:tcomponent);override;
{destructor destroy;override;}

published
.....

{ Published declarations }
end;

procedure Register;




implementation

uses ...;




constructor Tfznbox.create(AOwner:tcomponent);
begin
inherited create(AOwner);
....
end;

procedure tfznbox.paint;
var
myBitmap: TBitmap;
MyRect, MyOther: TRect;
begin
inherited paint;
.....
end;

procedure tfznbox.click;
begin
....
form1.repaint;
end;

procedure tfznbox.dblclick;
//type
//mytexts=array[0..20] of string;
var
begin
.....

ok....it has been passed
 
多人接受答案了。
 
后退
顶部