Using controls in the way of inheritance in Delphi

Source: Internet
Author: User
Tags inheritance integer

Before writing code, always make the main unit full brim; Now more like the control more independent function as a unit, overwriting properties, overloaded methods ... Even if only a little bit and the default is different, also like to be independent. Just use the Tlistbox, you need to be able to drag elements, double-click Delete.

Unit ListBox2;
 
Interfaceuses
  system.classes, Vcl.controls, Vcl.stdctrls, system.types;
 
Type
  TListBox2 = Class (Tcustomlistbox)
  protectedprocedure DragOver (source:tobject; X:integer; Y:integer; State:tdragstate; var 

accept:boolean); Override;procedure DblClick; Override;
  Publicconstructor 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) dobeginparent: = self;
    Align: = Alleft;
    Items.commatext: = ' a,b,c,d,e,f,g ';
  End;
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.