home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / oop.swg / 0008_OOP-EXMP.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  72 lines

  1. {
  2.   I am trying to teach myself about Object orientated Programming and about
  3. 'inheritence'. This is my code using Records.
  4.  
  5. Have a look at 'Mastering Turbo Pascal 6' by tom Swan, pg. 584 and on.
  6. Briefly, without Objects, code looks like this:
  7. }
  8.  
  9. DateRec = Record
  10.   Month: Byte;
  11.   day:   Byte;
  12.   year:  Word;
  13. end;
  14.  
  15. Var
  16.   today: DateRec;
  17.  
  18. begin
  19.   With today do
  20.   begin
  21.    month:= 6;
  22.    day  := 6;
  23.    year := 1992;
  24.   end;
  25. ...
  26. more code..
  27. end.
  28.  
  29. With Objects, code looks like this:
  30.  
  31. Type
  32.   DateObj = Object
  33.     month: Byte;                   {note data and methods are all}
  34.     day:   Byte;                   {part of the Object together  }
  35.     year:  Word;
  36.     Procedure Init(MM, DD, YY: Word);
  37.     Function StringDate: String;
  38.   end;
  39.  
  40. Var
  41.   today: DateObj;
  42.  
  43. Procedure DateObj.Init(MM, DD, YY: Word); {always need to initialise}
  44. begin
  45.   Month:= MM;
  46.   Day  := DD;
  47.   year := YY;
  48. end;
  49.  
  50. Function DateObj.StringDate: String;
  51. Var
  52.   MStr, Dstr, YStr: String[10];
  53. begin
  54.   Str(Month, MStr);
  55.   Str(Day, DStr);
  56.   Str(Year, YStr);
  57.   StringDate := MStr + '/' + DStr + '/' + YStr
  58. end;
  59.  
  60. begin         {begin main Program code}
  61.   today.Init(6,6,1992);
  62.   Writeln('The date is ', today.StringDate)
  63.   Readln
  64. ..
  65. other code..
  66. end.
  67.  
  68. Hope this helps.  Read all the example code you can, and try the Turbo-
  69. vision echo (not yet on Fidonet, but nodes were listed on here
  70. recently).  You can fidonet sysop Pam Lagier at TurboCity BBS 1:208/2
  71. For a node list.
  72.