如何使用计时器为字符串网格中的字符串插入排序设置动画?

时间:2012-04-26 10:48:27

标签: arrays delphi sorting

我正在尝试使用计时器移动字符串,以便在我的delphi程序中为插入排序设置动画。有人可以提供任何建议吗?

procedure TForm1.Button1Click(Sender: TObject);
var
current_position, index, count : integer ;
temp : string ;


begin
current_position := 0 ; //start insertion sort
repeat
current_position := current_position + 1 ; //set up pointers
index := 0 ;
while index <= current_position do
 begin
 if word[index] > word[current_position] then
  begin
  temp:= word[current_position];
   for count := current_position downto index + 1 do
    begin
    word[count]:= word[count-1]
    end;
    word[index]:= temp;
   end;
   index:= index + 1
  end;
 until current_position = 9 ;

 for current_position := 0 to 9 do
 StringGrid1.Cells[0,current_position]:= word[current_position];

end;

1 个答案:

答案 0 :(得分:0)

您只需在代码中插入Sleep(<milliseconds>);Application.ProcessMessages;即可减慢速度并显示进度。那个does introduce some problems/unwanted behaviours,所以你应该小心。