delphi property 实例(包含数组属性)

来源:互联网 发布:锤子手机usb网络共享 编辑:程序博客网 时间:2024/06/05 17:24
unit Unit2;interfacetype  TPerson=class(TObject)private   FAge:Integer;   FName:string;   FDegree:array[0..3] of string;      function getAge: Integer;   procedure setAge(const Value: Integer);   function getName: string;   procedure setName(const Value: string);   function getDegree(mindex: Integer): string;   procedure setDegree(mindex: Integer; const Value: string);public   property Age: Integer read getAge write setAge;   property Name:string  read getName write setName;   property Degree[mindex:Integer]:string read getDegree write setDegree;   constructor create;end;implementation{ TPerson }constructor TPerson.create();begin  FAge:=100;  FName:='小明';  FDegree[0]:='本科以下';  FDegree[1]:='本科';  FDegree[2]:='硕士';  FDegree[3]:='博士及以上';end;function TPerson.getAge: Integer;begin   Result:= FAge;end;function TPerson.getDegree(mindex: Integer): string;begin   Result:=FDegree[mindex];end;function TPerson.getName: string;begin  Result:=FName;end;procedure TPerson.setAge(const Value: Integer);begin   FAge:=Value;end;procedure TPerson.setDegree(mindex: Integer; const Value: string);begin    FDegree[mindex]:=Value;end;procedure TPerson.setName(const Value: string);begin  FName:=Value;end;end.

0 0