Getting started with classes (7): traverse all parent classes of a form

Source: Internet
Author: User
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; button3: tbutton; button4: tbutton; Procedure submit (Sender: tobject ); end; var form1: tform1; implementation {$ R *. DFM} // procedure tform1.button1click (Sender: tobject); begin showmessage (self. classname); {tform1-form1 class name} showmessage (self. classparent. classname); {parent class name of tform-form1} showmessage (self. classparent. classparent. classname); {tcustomform-form1 Grandpa class name} end; // procedure tform1.button2click (Sender: tobject); var myclass: tclass; {tclass is a class reference of tobject; it has the same functions as tobject, but in short it is not a type} begin {object's classtype method returns the object's tclass} showmessage (self. classtype. classname); {tform1-form1 class name} myclass: = self. classtype; showmessage (myclass. classname); {tform1-form1 class name} end; // procedure tform1.button3click (Sender: tobject); var myclass: tclass; begin {the object's classparent method returns tclass, you can assign the object classparent to the tclass variable} myclass: = self. classtype; showmessage (myclass. classname); {tform1-form1 class name} myclass: = myclass. classparent; showmessage (myclass. classname); {parent class name of tform-form1} myclass: = myclass. classparent; showmessage (myclass. classname); {tcustomform-form1 Grandpa class name} end; // traverses all parent classes of the form procedure tform1.button4click (Sender: tobject); var myclass: tclass; begin myclass: = self. classtype; while myclass nil do begin showmessage (myclass. classname); myclass: = myclass. classparent; end; {displayed in sequence: tform1 tform tcustomform tscrollingwincontrol twincontrol tcontrol tcomponent tpersistent tobject} end; end.
 
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.