Strange behaviour of function Sleep() used in repeat until in Delphi

前端 未结 4 1310
走了就别回头了
走了就别回头了 2021-01-19 01:28

I have function which is reaction on button click. When I click on the button it should start repeat and write values form an array and show them in labels on main form. Pro

4条回答
  •  无人共我
    2021-01-19 02:10

    I used two timers to update "slowly" some values (so that the user can see the progress) without slowing down the application or, in the worst case, the system.

    //  "weights" for old and new value; I was working on integers
    var
      Wa: integer =  1;
      Wb: integer =  9;
      Wt: integer = 10;
    
    //  interval of 1000 ms, of course
    procedure frmMain.T1000Timer(Sender: TObject);
    begin
      Wa:= 1;
      nValue:= calculate_new_value;
    end;
    
    //  100 ms interval
    procedure frmMain.T100Timer(Sender: TObject);
    begin
      Wb:= Wt -Wa;
      //  displayed value, ie gauge.progress, or something.Value, etc.
      sam.Value:= Round( (Wb *sam.Value +Wa *nValue) /Wt );
      if Wa < Wt then Inc(Wa);
    end;
    

提交回复
热议问题