Ross Levis wrote:
I have a question regarding the use of "as" in this statement.

 (RadioGroup1.Controls[0] as TRadioButton).SetFocus;


I've always done it like this:
    TRadioButton(RadioGroup1.Controls[0]).SetFocus;

Is one more efficient or beneficial than the other?

For a standard TRadioGroup you can be pretty much assured that everything in the Controls collection is a TRadioButton, so doing the unchecked typecast is probably safe.

Depending on your needs you might want to go as far as something like the following:

  if RadioGroup1.Controls[0] is TRadioButton then
    TRadioButton(RadioGroup1.Controls[0]).SetFocus;

Which provides the most protection; avoiding raising the exception on the chance that Controls[0] isn't a TRadioButton.

Stephen Posey
[EMAIL PROTECTED]

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to