Now the use of controls, more like inheritance

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Previously written code, is always the main unit to get full to the brim; now it is more like the control independent function as a unit, rewriting the attribute, overloaded methods... Even if only a little and the default is different, also like independence.

Just use TListBox, need to be able to drag element, click delete.

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.

Test:

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Bob at December 04, 2013 - 12:26 AM