home *** CD-ROM | disk | FTP | other *** search
/ Delphi 4 Bible / Delphi_4_Bible_Tom_Swan_IDG_Books_1998.iso / source / DAYNAMES / ArrayP.pas < prev   
Pascal/Delphi Source File  |  1998-05-12  |  1KB  |  63 lines

  1. {$APPTYPE CONSOLE}
  2.  
  3. { You can compile this program in the Delphi IDE or using the Delphi command
  4.   line compiler.
  5.  
  6.   To compile this program using the command line compiler, get to a DOS
  7.   prompt, make sure the system path refers to Delphi's bin directory
  8.   (see chapter 21), and enter the following command:
  9.  
  10.   dcc32 -cc arrayp
  11.  
  12.   Regardless of how you compile this program, you will probably want to run
  13.   this from a DOS prompt, so you can more easily see the output
  14.  
  15.   Enter arrayp to run the program. }
  16.  
  17. program ArrayProperties;
  18.  
  19. uses SysUtils;
  20.  
  21. type
  22.  
  23.   TDayNames = class
  24.   private
  25.     function GetName(N: Integer): String;
  26.   protected
  27.    property DayStr[N: Integer]: String read GetName; default;
  28.   end;
  29.  
  30. function TDayNames.GetName(N: Integer): String;
  31. begin
  32.   if (N < 0) or (N > 6) then
  33.     raise ERangeError.Create('Array index out of range');
  34.   case N of
  35.     0: Result := 'Sunday';
  36.     1: Result := 'Monday';
  37.     2: Result := 'Tuesday';
  38.     3: Result := 'Wednesday';
  39.     4: Result := 'Thursday';
  40.     5: Result := 'Friday';
  41.     6: Result := 'Saturday';
  42.   end;
  43. end;
  44.  
  45. var
  46.   DayNames: TDayNames;
  47.   I: Integer;
  48.  
  49. begin
  50.   DayNames := TDayNames.Create;
  51.   try
  52.     Writeln('Default property (DayNames[I])');
  53.     for I := 0 to 6 do
  54.       Writeln(DayNames[I]);
  55.     Writeln;
  56.     Writeln('Named property (DayNames.DayStr[I])');
  57.     for I := 6 downto 0 do
  58.       Writeln(DayNames.DayStr[I]);
  59.   finally
  60.     DayNames.Free;
  61.   end;
  62. end.
  63.