Controls attributes and small exercises inheriting the tshape class

Source: Internet
Author: User
In this example:


Code file:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tmyshape = Class (tshape) protected procedure cmmouseenter (VAR message: tmessage); message cm_mouseenter; Procedure cmmouseleave (VAR message: tmessage); message cm_mouseleave; end; tform1 = Class (tform) Panel1: tpanel; button1: tbutton; button2: tbutton; procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.button1click (Sender: tobject); const W = 50; H = 50; var shape: tmyshape; begin shape: = tmyshape. create (Self); shape. parent: = Panel1; shape. width: = W; shape. height: = H; randomize; shape. left: = random (panel1.clientwidth-W); shape. top: = random (panel1.clientheight-h); shape. brush. color: = random ($ ffffff); end; Procedure tform1.button2click (Sender: tobject); var I: integer; begin if panel1.controlcount = 0 Then exit; randomize; I: = random (panel1.controlcount-1); panel1.controls [I]. free; end; {tmyshape} procedure tmyshape. cmmouseenter (VAR message: tmessage); const S = 'the current % s color value is: %. 6x'; var wctrl: twincontrol; begin wctrl: = parent; while wctrl. hasparent do wctrl: = wctrl. parent; If wctrl is tform then tform (wctrl ). caption: = format (s, [classname, brush. color]); inherited; end; Procedure tmyshape. cmmouseleave (VAR message: tmessage); const S = 'form1 '; var wctrl: twincontrol; begin wctrl: = parent; while wctrl. hasparent do wctrl: = wctrl. parent; If wctrl is tform then tform (wctrl ). caption: = s; inherited; end.
 

Form file:

object Form1: TForm1  Left = 0  Top = 0  Caption = 'Form1'  ClientHeight = 212  ClientWidth = 395  Color = clBtnFace  Font.Charset = DEFAULT_CHARSET  Font.Color = clWindowText  Font.Height = -11  Font.Name = 'Tahoma'  Font.Style = []  OldCreateOrder = False  PixelsPerInch = 96  TextHeight = 13  object Panel1: TPanel    Left = 8    Top = 8    Width = 297    Height = 193    Caption = 'Panel1'    TabOrder = 0  end  object Button1: TButton    Left = 311    Top = 40    Width = 75    Height = 25    Caption = #28155#21152    TabOrder = 1    OnClick = Button1Click  end  object Button2: TButton    Left = 311    Top = 85    Width = 75    Height = 25    Caption = #38543#26426#21024#38500    TabOrder = 2    OnClick = Button2Click  endend
 

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.