我在学习类时定义了如下语句
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;type
  showbutton=class(tbutton)
  public
  procedure show;
  end;  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  but1:showbutton;
implementation{$R *.DFM}
procedure showbutton.show;
begin
showmessage('1234');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
but1:=showbutton.create;
end;end.
但是在编译时出现如下错误
not enough actual parameters 
我认为我的类定义的没有错误 create中应加入什么参数呢? 

解决方案 »

  1.   

    你的类是从TButton下来的,当然要继承他的构造器啦。添加Application或者nil就是。
      

  2.   

    看一看TButton的构造函数,你就知道错在那里了!!!
      

  3.   

    我想这样可以var
      btn : TButton;  btn := TButton.Create(nil);
      with btn do
        begin
          name := 'bn' ;
          text := 'bn' ;
          top := 20 ;
          width := 40 ;
          left := 20 ;
          height := 10 ;
          parent := form1;    end;
      

  4.   

    这样。。
    加一个构造器
    Constructo Create(Aowner:Tobject);override;
    按CTRL+SHIFT+C后写:
    begin 
    inherited Create(Aowner);//self也行!
    //你想实现的功能代码!
    end;加一个析构函数。。
    Destructor Destroy;override;
    一样按CTRL+SHIFT+C后写:
    begin
    inherited destroy;
    end;
    这样就可以了。。
    不过你在生在对像完想SHOW出来的话一定要加一个。。
    比如你生成Button2
    那么要这样。
    button2:=showbutton.create(self);
    button2.parent:=form1;//容器,就是放Button2的地方。。
     这样就可以了。。
      

  5.   


    我添加下了如下代码为什么程序没有给我一个对话框出来呢?
    procedure TForm1.but1Click(Sender: TObject);
    begin
    but1.show(owner);
    end;end.
      

  6.   

    but1:=showbutton.create(self);  // 加上参数
    but1.show(owner);
      

  7.   

    下面的代码可以看看:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Buttons, StdCtrls, ExtCtrls, MyPanel, Db, DBTables;type
      TMyButton = Class(TButton)
        public
          Constructor Create(AOwner:TComponent);override;
          procedure show;
      end;
      TForm1 = class(TForm)
        Button1: TButton;
        MyPanel1: TMyPanel;
        Button2: TButton;
        Edit1: TEdit;
        Query1: TQuery;
        Button3: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    begin
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
    end;{ TMyButton }constructor TMyButton.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
    end;procedure TMyButton.show;
    begin
      showmessage('ok');
    end;procedure TForm1.Button3Click(Sender: TObject);
    var
     myButton : TMyButton;
    begin
     MyButton := TMyButton.Create(self);
     MyButton.Parent := self;
     MyButton.Left := 20;
     MyButton.Top := 20;
     MyButton.Width := 100;
     MyButton.Height := 22;
     MyButton.Caption := 'daf';
     MyButton.Visible := true;
     MyButton.show;
    end;end.
      

  8.   

    同意楼上说法,窗体继承得构造函数必须(AOwner)
    constructor TMyButton.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
    end;