请教小问题一个,代码如下://========================
  //aaa1:= Taaa.Create;
  aaa1.xx(4, 4);
//========================
aaa1这个对象,我如果不 create他,为什么都可以用,应该会出错啊?是个空指针啊。unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;  Taaa = class
      procedure xx(a, b: Integer);
  end;  Taa1 = class(Taaa)
      procedure xx(a, b: Integer);
  end;var
  Form1: TForm1;
  c: Integer;
  aaa1: Taaa;implementation{$R *.dfm}{ Taaa }procedure Taaa.xx(a, b: Integer);
begin
  c:= a - b;
end;{ Taa1 }procedure Taa1.xx(a, b: Integer);
begin
  c:= a + b;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
  //aaa1:= Taaa.Create;
  aaa1.xx(4, 4);
  showmessage(inttostr(c));
end;end.

解决方案 »

  1.   


    //1,创建派生类的时候,基类也创建了。今天恰好崩到这个问题//2, 基类,派生类加个构造函数,ShowMessage 看下,什么都知道了。
      

  2.   

    没加Create确实比较奇怪,没碰到过;
    楼主一次搞了这么多类,不怕罚款...
      

  3.   

    问了哈,我们经理,终于搞懂了,
    procedure xx(a, b: Integer);是个静态的方法,
    如果把这个方法后面加个virtual,如下:
    procedure xx(a, b: Integer);virtual;
    再用aaa1.xx(4, 4);就会出错了,呵呵!
      

  4.   

    To  w_tao8029(小小剑) 那是因为你没有在子类中的XX中Override与楼主问题无关