home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!yale.edu!ira.uka.de!news.belwue.de!eratu.rz.uni-konstanz.de!nyx.uni-konstanz.de!phfrom
- From: phfrom@nyx.uni-konstanz.de (Hartmut Frommert)
- Newsgroups: comp.lang.pascal
- Subject: Re: Constants in an Object
- Message-ID: <phfrom.183@nyx.uni-konstanz.de>
- Date: 21 Jul 92 08:05:26 GMT
- Article-I.D.: nyx.phfrom.183
- References: <1992Jul19.073015.1199@ecst.csuchico.edu>
- Sender: usenet@eratu.rz.uni-konstanz.de
- Organization: Dept. of Physics, University of Constance
- Lines: 43
-
- jwstuart@ecst.csuchico.edu (Jesse William Leo Stuart) writes:
-
- > Does anyone know of a way to include constants in a TP6.0 object
- >declaration?
-
- As in records you can have fields in objects which are constant after
- initialization, simply by declaring
-
- type
- TMyObject=object
- MyConst: Integer;
- ..
- constructor Init;
- end;
-
- constructor TMyObject.Init;
- begin
- MyConst := 345;
- ..
- end;
-
- What I didn't try up to now is
-
- const
- MyObject: TMyObject = (345);
-
- or thelike. I assume this failes because no memory is reserved for MyObject;
- this is done by the constructor call. For this reason I assume that objects
- cannot be initialized as constants, but only by
-
- var
- MyObject: TMyObject;
- ..
- MyObject.Init;
- ..
-
- Hope this helps.
- --
- Hartmut Frommert, LS Dehnen, Physics, | E-Mail: <phfrom@dknkurz1.bitnet>
- Univ of Constance, P.O.Box 55 60, | or <phfrom@nyx.uni-konstanz.de>
- D-W-7750 Constance, Germany | + SAVE THE WHALES ! BOYCOTT NORWAY ! +
- Phone: +49-(0)7531-88-3747 | + Whales R intelligent. Whale killers not. +
- + Whale killing is murder. Eating whales is cannibalism. Eat whale killers. +
-