In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; procedure formmouseup (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); Procedure formpaint (Sender: tobject); Procedure button1click (Sender: tobject ); procedure button2click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses gdipobj, gdipapi; var ptarr: array of tgppoint; I: integer = 0; Procedure tform1.formmouseup (Sender: tobject; button: tmousebutton; shift: tshiftstate; X, Y: integer); begin canvas. ellipse (X-2, Y-2, x + 2, Y + 2); Inc (I); setlength (ptarr, I); ptarr [I-1]. x: = x; ptarr [I-1]. y: = y; text: = inttostr (I); end; Procedure tform1.formpaint (Sender: tobject); var G: tgpgraphics; P: tgppen; begin G: = tgpgraphics. create (canvas. handle); P: = tgppen. create (aclred, 2); G. clear (aclwhite); {@ ptarr is required if it is a dynamic array, but the dynamic array itself is a pointer} G. drawpolygon (p, pgppoint (ptarr), length (ptarr); G. free; p. free; end; Procedure tform1.button1click (Sender: tobject); begin I: = 0; setlength (ptarr, I); repaint; text: = inttostr (I); end; procedure tform1.button2click (Sender: tobject); begin repaint; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 188 clientwidth = 264 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = podesktopcenter onmouseup = formmouseup onpaint = formpaint pixelsperinch = 96 textheight = 13 object button1: tbutton left = 98 Top = 155 width = 75 Height = 25 caption = #25830 #38500 taborder = 0 onclick = button1click end object button2: tbutton left = 179 Top = 155 width = 75 Height = 25 caption = #32472 #21046 taborder = 1 onclick = button2click endend