0

i have a program that am working on that increments the progressbar by a certain value after a number of executions. the problem is the progressbar is not updated correctly but viewing the value passed to the progressbar through the debugger indicates that the incrementing value is passed correctly. Progressbar max value is set to 100.

Here is my Snippet

 function ParseasArray(Const sInput: String): TMyArray;

var
  iCount, iIncrement, iSizeofArray, iStepper, iPercenter, iTester,
    iHolder: Integer;

  dDoubleCalcVal: Double;

begin
  iIncrement := 1;
  iPercenter := 10;
  iHolder := 1;

  iSizeofArray := Trunc(Length(sInput) / 2);
  SetLength(result, iSizeofArray);
  for iCount := 1 to iSizeofArray do
  begin
    // do some work
    dDoubleCalcVal := (((iCount) / iSizeofArray));
    iStepper := Trunc(dDoubleCalcVal * 100);

    iTester := Trunc((iPercenter * iSizeofArray) / 100);

    if iCount = iTester then
    begin
      Form1.Indicator.Position := iStepper;
      inc(iPercenter, 10);
    end;

    inc(iIncrement, 2);
  end;

end;

My IDE Version

Delphi XE7 Update 1

Thanks.

Xor-el
  • 242
  • 4
  • 11
  • This is expected. Of course your thread cannot update its GUI, when it is busy executing your loop! – Andreas Rejbrand Jan 28 '15 at 22:21
  • You haven't said what is wrong. What is the problem? – David Heffernan Jan 28 '15 at 22:27
  • yes but the funny thing is that if i do this if (iCount) mod (2) = 0 then begin Form1.Indicator.Position := iStepper; end; instead of this if iCount = iTester then begin Form1.Indicator.Position := iStepper; inc(iPercenter, 10); end; it works fine. – Xor-el Jan 28 '15 at 22:28
  • @ David, the progressbar is not updated correctly as per the proper number of times it is meant to. – Xor-el Jan 28 '15 at 22:29
  • Can't you tell us what the problem is? I've no idea yet what you mean. Please say more than "not updated correctly". Describe what should happen, and what does happen. – David Heffernan Jan 28 '15 at 22:30
  • @ david, as per my code above, the progressbar is meant to be updated 10 times but it gets updated just twice at random positions. – Xor-el Jan 28 '15 at 22:32
  • FWIW you can and should avoid floating point calcs. The arithmetic can all be done using integer ops. – David Heffernan Jan 28 '15 at 22:41
  • As Andreas said, you cannot expect the UI to respond when it's busy in a loop. And as David says, you need to be a lot more specific. This needs to be in your question, not in the comments. – Jerry Dodge Jan 29 '15 at 00:18
  • Just add Indicator.Refresh to verify.. – Sertac Akyuz Jan 30 '15 at 18:33

0 Answers0