For me it works without freezing.
My code:
procedure TForm1.shBubbleS1(var Tab: array of Integer);
var
i,j,x:Integer;
begin
for j:=1 to high(tab)-1 do
for i:= 1 to high(tab)-1 do
if Tab[i] > Tab[i+1] then
begin
x := Tab[i];
Tab[i] := Tab[i+1];
Tab[i+1] := x;
Sleep(100);
D(Tab,i,i+1);
end;
end;
procedure TForm1.D(tab: Array of Integer; a:Integer; b:Integer);
var
i,stX,stY,barW,space:Integer;
begin
if high(tab)+1 > 200 then space:=2
else space:=1;
barW:=((imgPlotno.Width-((high(tab)+1)*space)) div high(tab)+1)-1;
stY:=imgPlotno.Height-10;
stX:= 5;
imgPlotno.Canvas.Brush.Color:=clWhite; {cleaning}
imgPlotno.Canvas.FillRect(0,0,imgPlotno.Width,imgPlotno.Height);
for i:=1 to high(tab)+1 do
begin
if (i=a) or (i=b) then
imgPlotno.Canvas.Brush.Color:=clGreen
else
imgPlotno.Canvas.Brush.Color:=clBlue;
imgPlotno.Canvas.Rectangle(stX+ (i-1)*(barW+Space), stY,stX+ (i-1)*(barW+space)+barW,stY - tab[i]);
end
end;
procedure TForm1.Button21Click(Sender: TObject);
var
tab :array[0..4] of integer = (1,5,3,4,2);
begin
shbubbles1(tab);
end;