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 }
     procedure mpress(Sender:Tobject);//////////这里总报错!!!!!
  public    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure mpress(sender:Tobject);
begin
 showmessage('asdf');
end;procedure TForm1.Button1Click(Sender: TObject);
var
my:Tbutton;
begin
my:=Tbutton.Create(self);
my.Width:=10;
my.Top :=10;
my.Parent :=form1;
my.OnClick :=unit1.Form1.mpress ;end;
end.[Error] Unit1.pas(18): Unsatisfied forward or external declaration: 'TForm1.mpress'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'谢谢大家了!
self 和 nil 有什么区别啊?

解决方案 »

  1.   

    procedure mpress;create(self)是指Parent是调用的窗体, 当调用的窗体Free时, 此对象自动释放.
    create(nil)是指Parent是Nil, 此时, 必须用Free来释放, 否则一直在内存中.
      

  2.   

    procedure TForm1.mpress(sender:Tobject);//加tfORM1
    begin
     showmessage('asdf');
    end;
      

  3.   

    procedure Form1.mpress(sender:Tobject);  ///你不加TFrom1,他误认为你在form1中声明的过程没有定义所以报错在上面
    begin
     showmessage('asdf');
    end;