• 关于类的入门例子(1): 继承窗体


    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    
      {继承 TForm1 的类: TMyForm}
      TMyForm = class(TForm1)
         procedure Button1Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;  //声明 TForm1 的实例
      MyForm1: TMyForm;  //声明 TMyForm 的实例
    implementation
    
    {$R *.dfm}
    
    //Form1 上有两个按钮, Button1: 弹出信息; Button2: 创建并显示 MyForm1
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage('TForm1');
    end;
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      MyForm1 := TMyForm.Create(nil);
      MyForm1.Show;
    end;
    
    
    { TMyForm }
    //TMyForm1 被创建后, 应该和 TForm1 一摸一样;
    //Button2: 会继续创建并弹出新的 TMyForm1
    //Button1: 会弹出两条信息, 因为继承了一条
    procedure TMyForm.Button1Click(Sender: TObject);
    begin
      inherited;  //继承 Button1 原有的功能
      ShowMessage('TMyForm');
    end;
    
    end.
    
  • 相关阅读:
    JDBC事务--软件开发三层架构--ThreadLocal
    SQL查询-约束-多表
    SQL基本语法总结
    DDL
    ZOJ 1178 Booklet Printing
    ZOJ 1107 FatMouse and Cheese
    ZOJ 1099 HTML
    ZOJ 1041 Transmitters
    ZOJ 1095 Humble Numbers
    ZOJ 1105 FatMouse’s Tour
  • 原文地址:https://www.cnblogs.com/del/p/993524.html
Copyright © 2020-2023  润新知