Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5848857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:55:06+00:00 2026-05-22T12:55:06+00:00

How to use ProgressBar for SaveToFile method ? Actually I want to save a

  • 0

How to use ProgressBar for SaveToFile method ? Actually I want to save a resource to a file, and have progress bar update from 0% to 100% as it saves, how do I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:55:06+00:00Added an answer on May 22, 2026 at 12:55 pm

    You can make your own TResourceStream descendant like in the code below. But for large resources (and that’s probably the case, otherwise you wouldn’t have to see progress) it’s better to “wrap” this in a separate thread. Yell if you need help with that.

    type
      TForm1 = class(TForm)
        Button: TButton;
        ProgressBar: TProgressBar;
        procedure ButtonClick(Sender: TObject);
      private
        procedure StreamProgress(Sender: TObject; Percentage: Single);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    type
      TStreamProgressEvent = procedure(Sender: TObject;
        Percentage: Single) of object;
    
      TProgressResourceStream = class(TResourceStream)
      private
        FOnProgress: TStreamProgressEvent;
      public
        procedure SaveToFile(const FileName: TFileName);
        property OnProgress: TStreamProgressEvent read FOnProgress
          write FOnProgress;
      end;
    
    { TProgressResourceStream }
    
    procedure TProgressResourceStream.SaveToFile(const FileName: TFileName);
    var
      Count: Int64;
      Stream: TStream;
      BlockSize: Int64;
      P: PAnsiChar;
      WriteCount: Int64;
    begin
      if Assigned(FOnProgress) then
      begin
        Count := Size;
        if Count <> 0 then
        begin
          Stream := TFileStream.Create(FileName, fmCreate);
          try
            if Count < 500 then
              BlockSize := 5
            else
              BlockSize := Count div 50;
            P := Memory;
            WriteCount := 0;
            while WriteCount < Count do
            begin
              if WriteCount < Count - BlockSize then
                Inc(WriteCount, Stream.Write(P^, BlockSize))
              else
                Inc(WriteCount, Stream.Write(P^, Count - WriteCount));
              Inc(P, BlockSize);
              FOnProgress(Self, WriteCount / Count);
            end;
          finally
            Stream.Free;
          end;
        end;
      end
      else
        inherited SaveToFile(FileName);
    end;
    
    { TForm1 }
    
    procedure TForm1.ButtonClick(Sender: TObject);
    var
      Stream: TProgressResourceStream;
    begin
      ProgressBar.Min := 0;
      Stream := TProgressResourceStream.Create(HInstance, 'TFORM1', RT_RCDATA);
      try
        Stream.OnProgress := StreamProgress;
        Stream.SaveToFile('TForm1.dat');
      finally
        Stream.Free;
      end;
    end;
    
    procedure TForm1.StreamProgress(Sender: TObject; Percentage: Single);
    begin
      with ProgressBar do
        Position := Round(Percentage * Max);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use progress bar to show file upload progress. I'm currently using
I want to show a progress bar while downloading a file from the web
I have a multi-step BackgroundWorker process. I use a marquee progress bar because several
I want to use ProgressBar from netbeans GUI builder. Any example will be appreciated.
Basic Goal is that i have four progress bar and want to run them
In my SWT Application i wish to use a progress bar (org.eclipse.swt.widgets.ProgressBar) i found
I want to change a progress bar use SetValue(int),but it doesn't work,it always change
I am trying to use progress bar to show the progress of a script.
I am trying to use the basic progress bar however I am unable to
I have some progress bar (search results), which value is dynamically set on document.ready

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.