RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TProgressBar.Step Property

Specifies the amount that Position increases when the StepIt method is called.

Pascal
property Step: Integer;
C++
__property int Step;

Set Step to specify the granularity of the progress bar. Step should reflect the size of each step in the process tracked by the progress bar, in the logical units used by the Max and Min properties.  

When a progress bar is created, Min and Max represent percentages, where Min is 0 (0% complete) and Max is 100 (100% complete). If these values are not changed, Step is the percentage of the process completed before the user is provided with additional visual feedback. 

When the StepIt method is called, the value of Position increases by Step.  

C++ Examples: 

 

/*
This example reads bytes from a file in tenths of the size
of the file. The ProgressBar displays the status of each
1/10th step as it's read into the buffer.  This example
requires a TButton and a TProgressBar control on the form.
*/
#include <stdio.h>     // for FILE, fopen, fstat, fileno, fread and fclose
#include <sys\stat.h>  // for fstat and the stat struct
#include <Math.hpp>    // for Min

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  FILE *F;
  char MyData[2047];
  long BytesRead;

  F = fopen("../about.txt", "r");   // path relative to Debug
                                    // use a file larger than 2048 bytes to make it interesting.
  if (F)
  {
    struct stat statbuf;
    fstat(fileno(F), &statbuf);
    ProgressBar1->Max = statbuf.st_size;
    if (ProgressBar1->Max > 10)
    {
      ProgressBar1->Step = (ProgressBar1->Max)/10;
      ProgressBar1->Step = Min(ProgressBar1->Step, 2047);
    }
    else
      ProgressBar1->Step = ProgressBar1->Max;
    char *DataBuffer = new char[ProgressBar1->Step];
    for (ProgressBar1->Position = 0;
         ProgressBar1->Position < ProgressBar1->Max;
         ProgressBar1->StepIt())  // move the ProgressBar Position using StepIt
    {
      fread(DataBuffer, ProgressBar1->Step, 1, F);
      // Do this or the read will wrap and start over!
      ProgressBar1->Step =
        Min(ProgressBar1->Step, ProgressBar1->Max - ProgressBar1->Position);
    }
    delete DataBuffer;
    fclose(F);
  }
}

 

Delphi Examples: 

{
This example reads bytes from a file in tenths of the size
of the file. The ProgressBar displays the status of each
1/10th step as it's read into the buffer.  This example
requires a TButton and a TProgressBar control on the form.
} 
procedure TForm1.Button1Click(Sender: TObject);
const
  FName = 'about.txt';  // use a file larger than 2048 bytes to make it interesting.
var
  F: File;
  MyData: array[1..2048] of byte;
  BytesRead: LongInt;
begin
  AssignFile(F, FName);
  try
    Reset(F, 1);
    ProgressBar1.Max := FileSize(F);
    if (ProgressBar1.Max > 10) then
    begin
      // amount to move when StepIt method called
      ProgressBar1.Step := ProgressBar1.Max div 10;
      ProgressBar1.Step := Min(ProgressBar1.Step, 2048);
    end
    else
      ProgressBar1.Step := ProgressBar1.Max;
    while (ProgressBar1.Position < ProgressBar1.Max) do
    begin
      // read one Step size chunk of data to buffer
      BlockRead(F, MyData, ProgressBar1.Step, BytesRead);
      // move the ProgressBar Position using StepIt
      ProgressBar1.StepIt; // move by Step amount
      // Do this or the read will wrap and start over!
      ProgressBar1.Step :=
          Min(ProgressBar1.Step, ProgressBar1.Max - ProgressBar1.Position);

    end;
  finally;
    CloseFile(F);
  end;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!