Re: Manipulate objects by reference
- From: "Maarten Wiltink" <maarten@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 15 Sep 2005 10:18:57 +0200
"Adam Sandler" <corn29@xxxxxxxxxx> wrote in message
> for i := 0 to pred(ComponentCount) do
> if Components[i] is TwwDBEdit then
> Components[i].DataSource := ds;
> Like you mentioned .Name is avalable to Components in this context but
> it isn't clear to me that even though Delphi knows I'm working with
> TwwDBEdit types, wht are some of those type's properties not
Delphi does *NOT* know that you are working with a TwwDBEdit. *You* do,
because you've just tested for it.
Components[i] returns a TComponent. Every time. To use it as a TWhatever,
you have to cast it. You test beforehand so that you know the cast is
safe. The compiler does not look at the meaning of the cast, and does not
remember anything about it.