Re: Manipulate objects by reference



"Adam Sandler" <corn29@xxxxxxxxxx> wrote in message
news:1126719218.807807.34420@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[...]
> 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
> available???

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.

Groetjes,
Maarten Wiltink


.



Relevant Pages

  • Re: Manipulate objects by reference
    ... swansnow wrote: ... > if Componentsis TwwDBEdit then ... > Note the cast to the component type. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Manipulate objects by reference
    ... if Componentsis TwwDBEdit then ... Note the cast to the component type. ... Prev by Date: ...
    (comp.lang.pascal.delphi.misc)
  • Re: pointer_to_function?
    ... meaning a cast is _not_ used; other conversions are explicit, ... If your compiler doesn't warn you about an implicit conversion, odds are it's legal and meaningful*. ... You should only use a cast (therefore making an explicit conversion) when you're absolutely sure you know the warning is wrong -- and it usually isn't. ...
    (comp.lang.c)