我是delphi初学者,哪位能给我讲讲as的用法?

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/1435/1435900.xml?temp=.5868036
      

  2.   

    The as operator performs checked typecasts. The expressionobject as classreturns a reference to the same object as object, but with the type given by class. At runtime, object must be an instance of the class denoted by class or one of its descendants, or be nil; otherwise an exception is raised. If the declared type of object is unrelated to class
    梩hat is, if the types are distinct and one is not an ancestor of the other梐 compilation error results. 
    For example,with Sender as TButton dobegin
      Caption := '&Ok';
      OnClick := OkClick;
    end;The rules of operator precedence often require as typecasts to be enclosed in parentheses. For example,(Sender as TButton).Caption := '&Ok';