您的位置:程序门 -> delphi -> 语言基础/算法/系统设计



[bcb->delphi]自定义类为何会在关闭程序时出错


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


[bcb->delphi]自定义类为何会在关闭程序时出错[已结贴,结贴人:dreamnyj]
发表于:2007-02-27 00:33:13 楼主
由于最近这段日子感到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;
发表于:2007-02-27 01:30:431楼 得分:50
curhuman1.create(   );   换成curhuman1   :=   thuman.create;   试试
发表于:2007-02-27 01:32:512楼 得分:0
受教了....看来刚刚开始学真是犯这种低级错误。。。。多谢了


快速检索

最新资讯
热门点击