zoukankan      html  css  js  c++  java
  • 关于类的入门例子(4): property

    //类单元
    unit Person;
    
    interface
    
    type
      TPerson = class(TObject)
      private
        FName: string;
        FAge: Integer;
      public
        procedure SetName(const strName: string);
        procedure SetAge(const intAge: Integer);
        property Name: string read FName write SetName;
        property Age: Integer read FAge write SetAge;
      end;
    
    implementation
    
    { TPerson }
    
    procedure TPerson.SetName(const strName: string);
    begin
      FName := strName;
    end;
    
    procedure TPerson.SetAge(const intAge: Integer);
    begin
      if intAge<0 then FAge := 0  else FAge := intAge;
    end;
    
    end.
    
    //测试: uses Person; procedure TForm1.Button1Click(Sender: TObject); var PersonOne: TPerson; begin PersonOne := TPerson.Create; PersonOne.Name := '万一'; PersonOne.Age := 100; ShowMessage('姓名:' + PersonOne.Name + '; 年龄:' + IntToStr(PersonOne.Age)); //姓名:万一; 年龄:100 PersonOne.Free; end;
  • 相关阅读:
    mysqllog
    清理:db上面的过期的binlog,释放磁盘空间。 (转)
    linux下shell命令trap
    mvc
    uci随笔
    luci 随笔
    shell脚本 整数比较
    lua学习
    OPENWRT make menuconfig错误之一
    openwrt 中make的使用
  • 原文地址:https://www.cnblogs.com/del/p/993794.html
Copyright © 2011-2022 走看看