• 现在使用控件, 更喜欢继承(覆盖控件已有的函数,很奇怪的一种使用方式)


    以前写代码, 总是把主单元弄得满满当当; 现在更喜欢把控件比较独立的功能写成一个单元, 改写属性、重载方法...哪怕只有一点点和默认不同, 也喜欢独立出来.

    刚刚用到 TListBox, 需要能拖动元素、双击删除.


    unit ListBox2;
    
    interface
    
    uses
      System.Classes, Vcl.Controls, Vcl.StdCtrls, System.Types;
    
    type
      TListBox2 = class(TCustomListBox)
      protected
        procedure DragOver(Source: TObject; X: Integer; Y: Integer; State: TDragState; var Accept: Boolean); override;
        procedure DblClick; override;
      public
        constructor Create(AOwner: TComponent); override;
        procedure DragDrop(Source: TObject; X: Integer; Y: Integer); override;
      end;
    
    implementation
    
    { TListBox2 }
    
    constructor TListBox2.Create(AOwner: TComponent);
    begin
      inherited;
      DragMode := dmAutomatic;
    end;
    
    procedure TListBox2.DblClick;
    begin
      inherited;
      Items.Delete(ItemIndex);
    end;
    
    procedure TListBox2.DragDrop(Source: TObject; X, Y: Integer);
    begin
      inherited;
      Items.Exchange(ItemIndex, ItemAtPos(Point(X,Y), True));
    end;
    
    procedure TListBox2.DragOver(Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
    begin
      inherited;
      Accept := True;
    end;
    
    end.
    


    测试:


    uses ListBox2;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      with TListBox2.Create(Self) do begin
        Parent := Self;
        Align := alLeft;
        Items.CommaText := 'A,B,C,D,E,F,G';
      end;
    end;

    http://www.cnblogs.com/del/p/3210460.html

  • 相关阅读:
    iOS-触摸事件、手势识别、摇晃事件、耳机线控
    iOS-App生命周期
    Foundation框架—时间处理对象NSDate
    Kali linux渗透测试的艺术 思维导图
    数据结构_二叉树遍历
    数据结构_数值转换
    <转载>Mac下,使用sshpass让iterm2支持多ssh登录信息保存
    <转载>iTerm2使用技巧
    Maven打包编译找不到com.sun.crypto.provider.SunJCE类
    MySQL自动设置create_time和update_time
  • 原文地址:https://www.cnblogs.com/findumars/p/6027825.html
Copyright © 2020-2023  润新知