zoukankan      html  css  js  c++  java
  • 学习官方示例 System.TClass

    本例效果图:



    代码文件:
    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
    
  • 相关阅读:
    《这个杀手不太冷》
    vim 程序编辑器
    wireshark 过滤规则
    使用c函数库的两个函数strtok, strncpy遇到的问题记录
    memset 导致的段错误(segmentation fault)
    LNMP 环境搭建
    cgic 中文文档
    virtualBox 不能开启一个新任务的错误
    PPTP&L2TP&PPPOE client and server configure
    netperf安装及使用
  • 原文地址:https://www.cnblogs.com/del/p/1288767.html
Copyright © 2011-2022 走看看