• delphi 事件和属性的绑定


    TWindowState = (wsNormal, wsMinimized, wsMaximized);  
      
    TScrollingWinControl = class(TWinControl)  
    private  
      FHorzScrollBar: TControlScrollBar;  
      FVertScrollBar: TControlScrollBar;  
      FAutoScroll: Boolean;  
      FAutoRangeCount: Integer;  
      FUpdatingScrollBars: Boolean;  
      procedure CalcAutoRange;  
      procedure ScaleScrollBars(M, D: Integer);  
      procedure SetAutoScroll(Value: Boolean);  
      procedure SetHorzScrollBar(Value: TControlScrollBar);  
      procedure SetVertScrollBar(Value: TControlScrollBar);  
      procedure UpdateScrollBars;  
      procedure WMSize(var Message: TWMSize); message WM_SIZE;  
      procedure WMHScroll(var Message: TWMHScroll); message WM_HSCROLL;  
      procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;  
      procedure CMBiDiModeChanged(var Message: TMessage); message CM_BIDIMODECHANGED;  
    protected  
      procedure AdjustClientRect(var Rect: TRect); override;  
      procedure AlignControls(AControl: TControl; var ARect: TRect); override;  
      function AutoScrollEnabled: Boolean; virtual;  
      procedure AutoScrollInView(AControl: TControl); virtual;  
      procedure ChangeScale(M, D: Integer); override;  
      procedure CreateParams(var Params: TCreateParams); override;  
      procedure CreateWnd; override;  
      procedure DoFlipChildren; override;
    //此处所定义的就是 delphi 中object inspector 中的对象属性所显示的内容  TControlScrollBar类型, 读取FHorzScrollBar 通过SetHorzScrollBar写入  
     property HorzScrollBar: TControlScrollBar read FHorzScrollBar write SetHorzScrollBar;  
      property VertScrollBar: TControlScrollBar read FVertScrollBar write SetVertScrollBar;  
    end;

    上面是系统定义的,比较枯燥,下面是自己写的代码:

    unit Unit1;  
      
    interface  
      
    uses  
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
      Dialogs, StdCtrls;  
      
    type  
      TForm1 = class(TForm)  
        btn1: TButton;  
        edt1: TEdit;  
        procedure FormCreate(Sender: TObject);    //窗体创建事件  
        procedure btn1Click(Sender: TObject);     //butten 点击事件  
      private  
      public  
        //自己写的过程 显示位置  
        procedure OnTestPostionChange(Sender: TObject; Positon: Integer);  
      end;  
      
       // 类似于函数指针 of object 它必须指向某个对象的方法(即成员函数).  
      TTestEvent = procedure (Sender: TObject; Positon: Integer) of Object;  
      
      TTestClass = class(TObject)  
      private  
        FPosition: Integer;      // Position 属性用的  
        FOnPositionChange: TTestEvent; // OnPositionChange 属性  
        procedure SetPosition(const Value: Integer);  
      protected  
        procedure DoPositonChange;  
       // procedure doaaa: dynamic;  
      public  
        //属性 position 读取FPosition 写到SetPosition   integer 类型  
        property Position: Integer read FPosition write SetPosition;  
        //属性 onPositionChange  对象过程函数指针类型 读取FOnposition  写入 FOnPositionChange  
        property OnPositionChange: TTestEvent read FOnPositionChange write FOnPositionChange;  
      end;  
      
    var  
      Form1: TForm1;  
      test1: TTestClass;  
      
    implementation  
      
    {$R *.dfm}  
      
    procedure TForm1.FormCreate(Sender: TObject);  
    begin  
      test1 := TTestClass.Create;  
      test1.OnPositionChange := OnTestPostionChange;  
    end;  
      
    { TTestClass }  
      
    procedure TTestClass.DoPositonChange;  
    begin  
      if Assigned(FOnPositionChange) then  
        FOnPositionChange(Self,FPosition);  
    end;  
      
      
    procedure TTestClass.SetPosition(const Value: Integer);  
    begin  
      if Value <> FPosition then  
      begin  
        FPosition := Value;  
        DoPositonChange;  
      end;  
    end;  
      
    procedure TForm1.btn1Click(Sender: TObject);  
    begin  
      test1.Position := StrToInt(edt1.Text);  
    end;  
      
    procedure TForm1.OnTestPostionChange(Sender: TObject; Positon: Integer);  
    begin  
      showmessage('Postion = '+IntToStr(Positon));  
    end;  
      
    end.  

    执行过程就是:窗体创建(给OnPositionChange赋值)--点击button(读取edt1中的值)---之后调用setposition(也许这就是绑定好的了吧)----DOPositionchange----执行FOnPositionChange(也就是OnTestPostionChange)。。。

  • 相关阅读:
    OAuth 2.0 访问新浪、腾讯的资源服务器
    OAuth 2.0 Authorization Code授权方式详解
    linux权限补充:rwt rwT rws rwS 特殊权限
    异步服务器框架设计
    vsftpd常规操作指南
    folly学习心得
    中国人口趋势(19902035)
    hbase系统搭建
    过载保护
    穷人和富人
  • 原文地址:https://www.cnblogs.com/wildfox/p/5791193.html
Copyright © 2020-2023  润新知