Re: Referencing an object via variable.
From: AlanGLLoyd (alanglloyd_at_aol.com)
Date: 09/19/04
- Next message: Dr John Stockton: "Re: Text file question"
- Previous message: AlanGLLoyd: "Re: Sending Messages between applications"
- In reply to: Maarten Wiltink: "Re: Referencing an object via variable."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 19 Sep 2004 11:00:43 GMT
In article <414c0f2b$0$36861$e4fe514c@news.xs4all.nl>, "Maarten Wiltink"
<maarten@kittensandcats.net> writes:
>You can use the name, and Alan has told you how, but you already have
>the pointer you need at the start. It's often (not always) simpler to
>keep those pointers in some place of your own and get them from there
>when you need them again.
>
You might also like to think whether you actually do _need_ the name. Mostly
when Delphi calls an event handler it passes the reference of the
object-causing-the-event in its event handler parameter. Just typecast that
TObject to what it is.
Also one could store the reference to objects in the Tag property of some
enclosing object (maybe a TGroupBox or TPanel), typecast it into storage and
out of storage. Delphi also sometimes (as in a treeview) TTreeNode provides a
Data property for such storage.
Better programming style minimises use of the Name property, because you may
not know it, and getting the reference is somewhat of a pain, interrogating an
array or somthing like that, and it might change. Its only some random (even if
meaningful) text associated with the object which does everything.
If you have a fixed set of options, think of using enumerated values to
identify some option - these can be meaningfully named, and also used as an
index into an array holding (for example) objects, or descriptive strings. I
find that I am more likely to want the string from the object (usually for
display) than the object from the string.
Alan Lloyd
alanglloyd@aol.com
- Next message: Dr John Stockton: "Re: Text file question"
- Previous message: AlanGLLoyd: "Re: Sending Messages between applications"
- In reply to: Maarten Wiltink: "Re: Referencing an object via variable."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|