i have this code that drawing steps level bar on Tvirtualstringtree

i take the code from Here

this code is drawing level bar based on this variable and animated it with timer but i got problem i am trying to set**Percents** **variable to a random numbers start from 0 to 100 ** percent is real variable that set the level like that

the goal is to set the bar from 0 - 50 - 100 and chanfe those number via timer to get the same result of this image but using numbers from 0 to 100 instead of using 0.025 to animated

http://i.stack.imgur.com/Cvt24.gif

```
procedure TForm2.VirtualStringTree1BeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
procedure drawProgress(AWidth: Integer; APercent: Real; ASteps: Integer; ALeft: Integer = 1);
var
r: TRect;
h, n: Integer;
begin
if APercent > 1 then
APercent := 1
else if APercent = 0 then
Exit;//nothing to draw
h := Round(CellRect.Height / ASteps) - 1;
r.Top := CellRect.bottom - h - 1;
r.Left := ALeft;
r.Width := AWidth;
TargetCanvas.Brush.Color := clSkyBlue;
n := Ceil(APercent * ASteps);//how many rect to draw?
while n > 0 do begin
r.Height := h;
TargetCanvas.FillRect(r);
Dec(r.Top, 1 + h);
Dec(n);
end;
end;
begin
drawProgress(10, 1, 7);
drawProgress(30, Percents, 7, 1 + 10 + 1);
end;
```

i take the code from Here

this code is drawing level bar based on this variable and animated it with timer but i got problem i am trying to set

```
Percents := Percents + 0.025;
```

so i cannot set it to redraw the animated bar from 0 to 100 any idea how to tweak this ?the goal is to set the bar from 0 - 50 - 100 and chanfe those number via timer to get the same result of this image but using numbers from 0 to 100 instead of using 0.025 to animated

http://i.stack.imgur.com/Cvt24.gif

```
var
Percents: Real;
procedure TForm2.Timer1Timer(Sender: TObject);
begin
if Percents > 1 then
Percents := 0
else
Percents := Percents + 0.025;
VirtualStringTree1.Repaint;
end;
```

Percents := Percents + PercInt/100;

where you can put PercInt to 50 (percent). Do you have problem to generate random numbers?

```
procedure TFORM1.SoundLevel(Sender: TObject; Level: Integer);
begin
// this Level Value have maximum value that equals to 100
//so i needed to make the percents equals to that value to allow the tree redraw the animated level bar with the same value of the sound level
end;
```

currently by default the percent set randomly like so

```
global var
Percents: Real;
//initiate percent
Percents := 0.2;
if Percents > 1 then
begin
Percents := 0.5;
end
else
begin
Percents := Percents + 0.025;
end;
vstmca.Invalidate;
```

what i am trying to achieve to make percent equals to the sound level value the problem is that percent not completely set to actual integer

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

Open in new window

... where iLevel goes from 0 to 100, and result goes from 0.0 to 1.0