我在组建制作方法当中事件的创建和事件的处理(过程,函数)和方法不大清楚望大虾们提示。
例如:我在(继承Tedit)组建当中有onclick事件里先写事件过程,在组建使用时点击组建是发生已经写好的事件发生。
还有如果我不想有已经写好的组建事件(onclick)不知怎么做?。

解决方案 »

  1.   

    在Create的时候
    self.OnClick=yours method;
      

  2.   

    这个怎么编译通不过呢?unit customed;interfaceuses
      SysUtils, Classes, Controls, StdCtrls,dialogs;type
      TCustomEd = class(TCustomEdit)  private
       fed:tedit;
       constructor  create(aowner:tcomponent);
       procedure ss;
        { Private declarations }
      protected
        { Protected declarations }
      public
        { Public declarations }
      published
        { Published declarations }
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Samples', [TCustomEd]);
    end;constructor  TCustomEd.create(aowner:tcomponent);
     begin
     self.OnClick:=ss;
     end;
     procedure tcustomed.ss;
     begin
      showmessage('adf');
     end;
    end.
      

  3.   

    OnClick可以挂接的事件格式procedure ss(Sender:TObject);
      

  4.   

    procedure   ss(Sender: TObject);
      

  5.   

    编译通过后在组建使用时点击edit控件时怎么不发生事件呢?(showmessage事件)帮忙unit customed;interfaceuses
      SysUtils, Classes, Controls, StdCtrls,dialogs;type
      TCustomEd = class(Tedit)
      private
       fed:tedit;
       constructor  create(aowner:tcomponent);
       procedure ss(sender:tobject);
        { Private declarations }
      protected
        { Protected declarations }
      public
        { Public declarations }
      published
        { Published declarations }
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Samples', [TCustomEd]);
    end;constructor  TCustomEd.create(aowner:tcomponent);
     begin
     self.OnClick:=ss;
     end;procedure tcustomed.ss(sender:tobject);
     begin
      showmessage('adf');
     end;
    end.
      

  6.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    tmyEdit=class(TEdit)
    private
      procedure myOnClick(Sender:TObject);
    public
       constructor Create(AOwner: TComponent); override;
    end;var
      Form1: TForm1;implementation{$R *.dfm}{ tmyEdit }constructor tmyEdit.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      OnClick:=myOnClick;
    end;procedure tmyEdit.myOnClick(Sender: TObject);
    begin
     ShowMessage('Clicked Edit');
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
    edt:tmyEdit;
    begin
    edt:=tmyEdit.Create(Self);
    edt.Left:=100;
    edt.Top:=100;
    edt.Parent:=Self;
    end;end.
    //重写一写构造函数;当然要记得继承