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