Delphix provides a high-performance timer tdxtimer, which is basically the same as timer.
When we use timer, we seldom set interval to below 50 (this should be the limit of its accuracy );
You can use tdxtimer to set interval to 0, which means the speed is as fast as possible!
In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, dxclass, dxdraws, comctrls; Type tform1 = Class (tform) dxdraw1: tdxdraw; dxtimer1: tdxtimer; trackbar1: ttrackbar; Procedure formcreate (Sender: tobject); Procedure submit (Sender: tobject; lagcount: integer); Procedure trackbar1change (Sender: tobject); End; vaR form1: tform1; implementation {$ R *. DFM} procedure alert (Sender: tobject); begin alert: = alclient; trackbar1.align: = Albottom; trackbar1.height: = 23; trackbar1.showselrange: = false; trackbar1.min: = 0; trackbar1.max: = 500; trackbar1.position: = trackbar1.max Div 2; dxtimer1.interval: = trackbar1.position; randomize; end; Procedure destroy (Sender: tobject; lagcount: integer); var X1, Y1, X2, Y2: integer; begin {random position} X1: = random (dxdraw1.width); Y1: = random (dxdraw1.height); X2: = random (dxdraw1.width); Y2: = random (dxdraw1.height ); dxdraw1.surface. fill (0); with dxdraw1.surface. canvas do begin brush. color: = random ($ ffffff); {random color} ellipse (x1, Y1, X2, Y2); release; end; dxdraw1.flip; end; Procedure tform1.trackbar1change (Sender: tobject ); begin dxtimer1.interval: = trackbar1.position; end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 206 clientwidth = 339 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false oncreate = formcreate pixelsperinch = 96 textheight = 13 object dxdraw1: tdxdraw left = 24 Top = 24 width = 100 Height = 100 autoinitialize = true autosize = true color = clblack display. fixedbitcount = false display. fixedratio = true display. fixedsize = true Options = [doallowreboot, dowaitvblank, docenter, do3d, dodirectx7mode, dohardware, doselectdriver] surfaceheight = 100 surfacewidth = 100 taborder = 0 traces = end object trackbar1: ttrackbar left = 96 Top = 144 width = 150 Height = 28 taborder = 1 onchange = trackbar1change end object dxtimer1: tdxtimer activeonly = true enabled = true interval = 1000 ontimer = dxtimer1timer left = 144 Top = 24 endend