home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / pascal / 4477 < prev    next >
Encoding:
Internet Message Format  |  1992-07-20  |  1.6 KB

  1. Path: sparky!uunet!spool.mu.edu!yale.edu!ira.uka.de!news.belwue.de!eratu.rz.uni-konstanz.de!nyx.uni-konstanz.de!phfrom
  2. From: phfrom@nyx.uni-konstanz.de (Hartmut Frommert)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: Constants in an Object
  5. Message-ID: <phfrom.183@nyx.uni-konstanz.de>
  6. Date: 21 Jul 92 08:05:26 GMT
  7. Article-I.D.: nyx.phfrom.183
  8. References: <1992Jul19.073015.1199@ecst.csuchico.edu>
  9. Sender: usenet@eratu.rz.uni-konstanz.de
  10. Organization: Dept. of Physics, University of Constance
  11. Lines: 43
  12.  
  13. jwstuart@ecst.csuchico.edu (Jesse William Leo Stuart) writes:
  14.  
  15. >       Does anyone know of a way to include constants in a TP6.0 object 
  16. >declaration?
  17.  
  18. As in records you can have fields in objects which are constant after 
  19. initialization, simply by declaring
  20.  
  21. type
  22.   TMyObject=object
  23.     MyConst: Integer;
  24. ..
  25.     constructor Init;
  26.   end;
  27.  
  28. constructor TMyObject.Init;
  29. begin
  30.   MyConst := 345;
  31. ..
  32. end;
  33.  
  34. What I didn't try up to now is
  35.  
  36. const
  37.   MyObject: TMyObject = (345);
  38.  
  39. or thelike. I assume this failes because no memory is reserved for MyObject;
  40. this is done by the constructor call. For this reason I assume that objects 
  41. cannot be initialized as constants, but only by
  42.  
  43. var
  44.   MyObject: TMyObject;
  45. ..
  46. MyObject.Init;
  47. ..
  48.  
  49. Hope this helps.
  50. --
  51.  Hartmut Frommert, LS Dehnen, Physics, | E-Mail: <phfrom@dknkurz1.bitnet>
  52.  Univ of Constance, P.O.Box 55 60,     |     or  <phfrom@nyx.uni-konstanz.de>
  53.  D-W-7750 Constance, Germany  | + SAVE THE WHALES ! BOYCOTT NORWAY !        +
  54.  Phone: +49-(0)7531-88-3747   | + Whales R intelligent. Whale killers not.  +
  55. + Whale killing is murder. Eating whales is cannibalism. Eat whale killers. +
  56.