home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / delphi / kolekce / d56 / XMLCOMP.ZIP / test / model / DnPerson.pas < prev    next >
Pascal/Delphi Source File  |  2002-06-16  |  2KB  |  71 lines

  1. unit DnPerson;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes, Contnrs, DnAddress;
  7.  
  8. type
  9.   TPerson = class(TComponent)
  10.   private
  11.     FMiddlename: string;
  12.     FFirstname: string;
  13.     FLastname: string;
  14.     FInitials: string;
  15.     FAddress: TAddress;
  16.     function GetFullName: string;
  17.   public
  18.     constructor Create(aOwner: TComponent); override;
  19.   published
  20.     property Firstname: string read FFirstname write FFirstname;
  21.     property Middlename: string read FMiddlename write FMiddlename;
  22.     property Lastname: string read FLastname write FLastname;
  23.     property Initials: string read FInitials write FInitials;
  24.     property FullName: string read GetFullName;
  25.     property Address: TAddress read FAddress;
  26.   end;
  27.  
  28.   TPersonList = class(TComponentList)
  29.   private
  30.     function GetPerson(aIndex: Integer): TPerson;
  31.   public
  32.     property Person[aIndex: Integer]: TPerson read GetPerson;
  33.   end;
  34.  
  35. implementation
  36.  
  37. { TPerson }
  38.  
  39. constructor TPerson.Create(aOwner: TComponent);
  40. begin
  41.   inherited;
  42.   FAddress := TAddress.Create(Self);
  43. end;
  44.  
  45. function TPerson.GetFullName: string;
  46. begin
  47.   result := Initials;
  48.   if Firstname <> '' then
  49.     result := result + ' ' + Firstname;
  50.   if Middlename <> '' then
  51.     result := result + ' ' + Middlename;
  52.   if Lastname <> '' then
  53.     result := result + ' ' + Lastname;
  54. end;
  55.  
  56. { TPersonList }
  57.  
  58. function TPersonList.GetPerson(aIndex: Integer): TPerson;
  59. begin
  60.   Assert(Items[aIndex] is TPerson);
  61.   result := TPerson(Items[aIndex]);
  62. end;
  63.  
  64. initialization
  65.   RegisterClasses([TPerson]);
  66.  
  67. finalization
  68.   UnregisterClasses([TPerson]);
  69.  
  70. end.
  71.