Re: String access error in class
- From: "Maarten Wiltink" <maarten@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 28 Mar 2008 11:31:36 +0100
"E Sterrett" <bgreenf@xxxxxxxxxxxxx> wrote in message
news:ldSdnX6uUtYBp3HanZ2dneKdnZydnZ2d@xxxxxxxxxxxxxxx
If you need outside access, make properties. (If you don't, make
properties anyway, but make them protected. Then never touch the
fields again.)
Is there a reason for doing this? I do want everything to be readable
and writable.
In this case I don't see the difference between a public variable and a
property.
It's mostly just part of my system; I tend to do things always the
same way even if they're only needed sometimes. Allows me to substitute
finger macros for actual brain activity.
Properties allow you to put accessor methods between the value and its
storage. Sometimes, a value can be computed on demand from other values
and you don't even need storage. It's one way of keeping related things
synchronised.
Another way of keeping related things synchronised is to update one when
another changes. Write accessors can make that happen reliably.
Introducing a property also introduces the possibility to change how the
value is determined in a derived class if necessary. For instance, a Count
can be computed and unchangeable in the base class and become writeable in
a more advanced implementation.
<calling the inherited constructor>
Gotchya.. Do I have to call it by name like: TObject.Create
Or is there a generic parent object that can be used?
Type 'inherited', press F1, read help.
Explicitly calling TObject.Create would allocate a new TObject and hand you
a reference to it. You could cast your Self reference to TObject and call
Create on it, but you'd best forget immediately that such a thing is even
possible. In any case, it would stop working correctly if you decided to
change the derivation of your class from TObject to TPersistent because you
found out Assign is nice. 'Inherited Create' always does the right thing.
There is unfortunately no generic way to express the 'Create' part (which
I'd dearly like to have, in addition to Result and Self, to express
recursion
and inherited calls with parameters).
Groetjes,
Maarten Wiltink
.
- References:
- String access error in class
- From: E Sterrett
- Re: String access error in class
- From: Jamie
- Re: String access error in class
- From: Maarten Wiltink
- Re: String access error in class
- From: E Sterrett
- String access error in class
- Prev by Date: Scanline Enigma the Solutions
- Next by Date: Re: New to Delphi - Connecting to database using just code
- Previous by thread: Re: String access error in class
- Next by thread: Scanline Enigma the Solutions
- Index(es):