我自己编写了一个类Loading,创建了它的一个实例x;当我调用x.create时,系统报告'Project Project1.exe raised exception class EStackOverflow with message'Stack overflow'.Process stopped.Use Step or Run to continue.'我把代码附上,请问这是我哪里写错了啊?程序原有一个单元Unit1,我新建了一个Unit2,内容如下:
unit Unit2;interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,   Forms,Dialogs;type  Loading=class  //-----我的类
  i:integer;
end;implementation------------------------------------
Unit1很简单,内容如下:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation
uses unit2;{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var x:loading;//---------类的实例
begin
x.Create;//-----------这句话编译出错
x.i:=1;
x.Destroy;end;end.
 end.

解决方案 »

  1.   

    procedure TForm1.FormCreate(Sender: TObject);
    var x:loading;//---------类的实例
    begin
      x := Loading.Create; //-----------这样就不会编译出错啦
      x.i:=1;
      x.Free;        //推荐你别直接用Destroy,永远都照BORLAND所说的那样,用Free来代替
    end;
      

  2.   

    x := Loading.Create;
    是一定不要直接使用Destroy
      

  3.   

    是的!现在可以编译通过了!!!太好了!我是按一本delphi的教程上做的:先create,再destroy。唉!这本书以前就害过我一次了!
    谢谢楼上两位!谢谢!!!!真的很感谢:)