/1/
INTERVALS array When you scroll the Trackbar its Position property varies between its Min and Max values - they are 0 and 5 in this example. I am using the INTERVALS array to prepare an interval value for the timer for each step of the Trackbar. When the trackbar is at the left (Position = 0) the Timer.Interval becomes INTERVALS[0] = 1000, the longest interval, i.e. very slow rendering. Or when the trackbar is at the right (Position =5) then the Timer.Interval becomes 10 ms, the shortest interval, i.e. very fast renderung. Spending more typing work and probably requiring a bit more memory you could achieve the same effect by
case TrackBar1.Position of
0: Timer1.Interval := 1000;
1: Timer1.Interval := 300;
2: Timer1.Interval := 100;
3: Timer1.Interval := 40;
4: Timer1.Interval := 20;
5: Timer1.Interval := 10;
end;
/2/ Format functionYes, this function probably has the spirit of C in mind, but it is extremely useful. It has two arguments: the format mask string, and the argument list. The mask string contains symbol such as %s or %d, and they are replaced by the corresponding values from the argument list which is given as an array. %s is replaced by a string, %d is replaced by an integer value, %f by a floating point value (in this latter case the count of decimal places is given by the number before the "f" - "%.0f" means: "show the float with 0 decimals"). You must be careful to provide the value list in the same order as the symbols: in my example the first symbol is %d, therefore the first value in the array must be an integer; the second symbol is %.0f, and the second value must be a float (1000.0/INTERVALS[..]). If the Format function would not be used the string could also be created in the traditional way as
Label1.caption := 'Interval ' + IntToStr(INTERVALS[Trackbar1.Position]) +
' ms --> ' + IntToStr(round(1000.0/INTERVALS[Trackbar1.Position]) + ' frames/s';
/3/ TrackbarChange in FormCreateThis is simple initialization work: I want the timer to have the interval associated with the Trackbar.Position set up by the Object Inspector, and I want the label to display the associated numbers. This is exactly what is done by the Trackbar's OnChange handler, and that's why I call it. The event handler requires a Sender parameter which normally is the Trackbar. But since the Sender is not used by the current code I simply typed "nil" - a bit dirty, I agree...