zoukankan      html  css  js  c++  java
  • Delphi TFrame[3] 自定义显示、销毁、隐藏事件(onShow 、OnHide、OnDestroy)

    Delphi TFrame[3] 自定义显示、销毁、隐藏事件(onShow 、OnHide、OnDestroy)

    Frames中本身不存在显示onShow 、OnHide、OnDestroy事件

    方法1:通过设置框架的属性形式来模拟调用 frame的onshow过程

    type
      TFrame2 = class(TFrame)
        Edit1: TEdit;
      private
        { Private declarations }
        fmOnShow : TNotifyEvent;
        fmOnHide : TNotifyEvent;
        
        procedure fmSetOnShow(ps: TNotifyEvent);
        procedure fmSetOnHide(ph: TNotifyEvent);
        
        procedure FrameOnShowHide(var M: TMessage); message CM_SHOWINGCHANGED;
      public
        { Public declarations }
        property OnShow : TNotifyEvent write fmSetOnShow;            //通过设置框架的属性形式来模拟调用 frame的onshow过程
        property OnHide : TNotifyEvent write fmSetOnHide;
      end;
    
    implementation
    
    {$R *.dfm}
    
    { TFrame2 }
    
    procedure TFrame2.fmSetOnHide(ph: TNotifyEvent);
    begin
       fmOnHide := ph;
    end;
    
    procedure TFrame2.fmSetOnShow(ps: TNotifyEvent);
    begin
      fmOnShow := ps;
    end;
    
    procedure TFrame2.FrameOnShowHide(var M: TMessage);
    begin
      inherited;
      
      if Showing then
      if Assigned( fmOnShow ) then
          fmOnShow( Self )
      else
        if Assigned( fmOnHide ) then
          fmOnHide( Self );
    end;
    

    调用:

        procedure FrameShiJian(Sender: TObject);
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FrameShiJian(Sender: TObject);
    begin
      Frame2.Edit1.Text:='Hi,Delphi';
      ShowMessage('hi,滔Roy');
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Frame2.OnShow:=FrameShiJian;  //放在onshow之前
    end;

    方法2:继承 AfterConstruction 和 BeforeDestruction,类似OnCreate 和 OnDestroy

    type
      TFrame3 = class(TFrame)
        Label1: TLabel;
        Image1: TImage;
      private
        { Private declarations }
      public
        { Public declarations }
        procedure AfterConstruction; override;    //类似OnCreate事件
        procedure BeforeDestruction; override;    //类似OnDestroy事件
      end;
    
    implementation
    
    {$R *.dfm}
    
    { TFrame3 }
    
    procedure TFrame3.AfterConstruction;
    begin
      inherited;
      label1.Caption:='Hi,滔Roy!';
    end;
    
    procedure TFrame3.BeforeDestruction;
    begin
      inherited;
    
    end;
    

      

    创建时间:2021.12.16  更新时间:

    博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你所有帮助,谢谢!
  • 相关阅读:
    jxl读和取Excel文件
    Studio for WPF:定制 C1WPFChart 标记
    为C1Chart for WPF添加自定义标题、坐标轴单位标签以及旋转坐标轴注释
    自定义饼图(PieChart)各个PieSlice的外观
    vue组件
    vue双向绑定
    第一个Vue程序
    vue入门介绍
    js生成随机固定长度字符串的简便方法
    JavaScript 函数式编程读书笔记1
  • 原文地址:https://www.cnblogs.com/guorongtao/p/15697172.html
Copyright © 2011-2022 走看看