学习官方示例 - System.TClass
2008-09-11 00:38
411 查看
本例效果图:
代码文件:
窗体文件:
代码文件:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) ListBox1: TListBox; Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} {获取 Button1 的父类} procedure TForm1.Button1Click(Sender: TObject); var ClassRef: TClass; begin ListBox1.Clear; ClassRef := Sender.ClassType; while ClassRef <> nil do begin ListBox1.Items.Add(ClassRef.ClassName); ClassRef := ClassRef.ClassParent; end; end; {获取 ListBox1 的父类} procedure TForm1.Button2Click(Sender: TObject); var ClassRef: TClass; begin ListBox1.Clear; ClassRef := ListBox1.ClassType; while ClassRef <> nil do begin ListBox1.Items.Add(ClassRef.ClassName); ClassRef := ClassRef.ClassParent; end; end; {获取当前 Form 的父类} procedure TForm1.Button3Click(Sender: TObject); var ClassRef: TClass; begin ListBox1.Clear; ClassRef := Self.ClassType; while ClassRef <> nil do begin ListBox1.Items.Add(ClassRef.ClassName); ClassRef := ClassRef.ClassParent; end; end; end.
窗体文件:
object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 147 ClientWidth = 282 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object ListBox1: TListBox Left = 0 Top = 0 Width = 161 Height = 147 Align = alLeft ItemHeight = 13 TabOrder = 0 ExplicitHeight = 155 end object Button1: TButton Left = 184 Top = 24 Width = 75 Height = 25 Caption = 'Button1' TabOrder = 1 OnClick = Button1Click end object Button2: TButton Left = 184 Top = 64 Width = 75 Height = 25 Caption = 'Button2' TabOrder = 2 OnClick = Button2Click end object Button3: TButton Left = 184 Top = 104 Width = 75 Height = 25 Caption = 'Button3' TabOrder = 3 OnClick = Button3Click end end
相关文章推荐
- 学习官方示例 - System.Hi、System.Lo
- 学习官方示例 - System.Assigned
- 学习官方示例 - System.Frac: 返回小数部分
- 学习官方示例 - System.RunError
- 学习官方示例 - System.RunError
- unity3d官方教学示例之SurivalShooter学习笔记
- Android 官方示例:android-architecture 学习笔记(七)之todo-mvp-dagger
- 学习官方示例 - TApplication.ExeName
- 学习官方示例 - TApplication.OnException
- Log4j2官方文档翻译、学习笔记之三——Layouts的分类及常用类型示例
- 【ExtJS 4.x学习教程】(1)类系统(Class System)
- Android 官方示例:android-architecture 学习笔记(六)之todo-mvp-contentproviders
- EXTJS 5 学习笔记1 - Class System
- backbone官方Todo示例分解学习
- 学习官方示例 - TApplication.OnShowHint
- 官方C++示例 InfraredBasics-D2D的学习及Kinect深度数据的获取、保存
- 学习官方示例 - SysUtils.EncodeDate、EncodeTime、StrToDate、StrToTime、StrToDateTime
- Swift教程_通过改造官方Sample学习Swift(一)_Element示例简介
- ThinkPHP学习(二)官方文档的一个数据增查小示例
- 苹果官方示例代码《LazyTableImages》异步加载图片的学习记录