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?

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

is a direct compile-time typecast with no error checking at all. Very fast, ie. no time at all, but can be unsafe _if_ you are not 100% sure that the object you are typecasting is what you think it is.

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

is a run-time typecast that checks the typecast is valid for that class. Slower, but safer for those cases where the object may not be what you think it should be.

--
Sly


This message and its attachments may contain legally privileged or confidential 
information. This message is intended for the use of the individual or entity 
to which it is addressed. If you are not the addressee indicated in this 
message, or the employee or agent responsible for delivering the message to the 
intended recipient, you may not copy or deliver this message or its attachments 
to anyone. Rather, you should permanently delete this message and its 
attachments and kindly notify the sender by reply e-mail. Any content of this 
message and its attachments, which does not relate to the official business of 
the sending company must be taken not to have been sent or endorsed by the 
sending company or any of its related entities. No warranty is made that the 
e-mail or attachment(s) are free from computer virus or other defect.
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to