首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

[BCB->Delphi]自定义类为何会在关闭程序时出错解决方法

2012-02-25 
[BCB-Delphi]自定义类为何会在关闭程序时出错由于最近这段日子感到bcb越来越困难,所以打算转型成delphi,

[BCB->Delphi]自定义类为何会在关闭程序时出错
由于最近这段日子感到bcb越来越困难,所以打算转型成delphi,正在学习OP语法
下面这段代码编译正常通过,但是会出错,望前辈指点

implementation

{$R   *.dfm}
    Type
        THuman   =   class           {没有指定父类应该是从TObject派生吧}
        public
        Sex   :   Boolean;
        Age:Integer;
        Function   Retire(IntAge:Integer):Boolean;
      End;

Function   THuman.Retire(IntAge:Integer):Boolean;
    Begin

          if   IntAge   > =   60   then
              Result   :=   true
          else
              Result   :=   false;

    End;

procedure   TForm1.Button1Click(Sender:   TObject);

    Var
    CurHuman1:THuman;
begin
      CurHuman1.Create(   );{关键位置,如果我不在这里使用Create程序编译完执行下一句的时候会出错,意思可能是没有初始化}
      CurHuman1.Age   :=   StrToInt(Edit1.Text);

      if   CurHuman1.Retire(CurHuman1.Age)   then
            Label2.Caption:= '已经退休 '
            else
            Label2.Caption:= '正在工作 ';


    CurHuman1.Free();{关键位置,这句我无论是注释掉还是让其运行,程序最后都会抛开异常,   windows显示程序异常关闭}


end;

[解决办法]
CurHuman1.Create( ); 换成CurHuman1 := THuman.Create; 试试

热点排行