Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Solved How To Fire Up the event handler "OnProgress" of TImage ?

Discussion in 'Delphi Programming' started by Bravesaw, Aug 14, 2018.

  1. Bravesaw
    Online

    Bravesaw DF Junior

    hello my Friends:
    i need to get the event "OnProgress" of TImage work...
    i have this code here:
    Code:
    .....
    
    Image1.Picture.LoadFromFile(FileName);
    ....
    procedure TForm1.Image1Progress(Sender: TObject; Stage: TProgressStage;
      PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
    begin
      case Stage of
        psStarting:  ProgressBar1.Position := 0;
        psRunning:
          begin
            ProgressBar1.Position := PercentDone;
          //  ProgressBar1.Update;
            Application.ProcessMessage;
          end;
        psEnding: ProgressBar1.Position := 0;
      end
    end;
    nb:===== the size of the images that the timage can load its more bigger and the smallest can be 10 MegaByte ===
     
    paramithas, Lgogo and migoct like this.
  2. vcorp
    Offline

    vcorp DF Junior

    wich delphi version are you using? Application.ProcessMessages is deprecated
    btw try to put it before progressbar position
     
  3. Bravesaw
    Online

    Bravesaw DF Junior

    Thank you very much Mr: vcorp
    My Delphi version is Delphi berlin update 2 .
    This question i solved the day i was post it because i forget to verify the event onprogress of the TImage -(it was not Linked with thier own procedure which mean i didn't see it empty .....i was totally like a blind man ..hhhh)- sorry ...
    finally it's work with me just by linking the image event property with thier own procedure from the object inspector ... it was my fault ..... sorry.
    but Even that ... this Event deserve one Remark about the way of work:
    *) the PercentDone doesn't work properly ... because the progressbar never complete the progress untill 100% ...She always complete at an average of 90% or 85% and this is completlly appear when we desable this line from the case above :
    // psEnding: ProgressBar1.Position := 0;

    With best Regards: BraveSaw....:);)
     
  4. vcorp
    Offline

    vcorp DF Junior

    try using the round function maybe it will solve the problem.
    Btw good luck with your project.
     
    Bravesaw likes this.
  5. Bravesaw
    Online

    Bravesaw DF Junior

    finally this will fix all:
    Code:
    procedure TForm1.Image1Progress(Sender: TObject; Stage: TProgressStage;
      PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
    begin
      case Stage of
        psStarting: ProgBar_Drag.Position := 0;
        psRunning:
          begin
            ProgBar_Drag.Position := PercentDone;
          end;
        psEnding:
          begin
            ProgBar_Drag.Position := PercentDone;
            Timer1.Enabled := True; // Interval := 500;
          end;
      end
    
    end;
    
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      Timer1.Enabled := False;
      ProgBar_Drag.Position := 0;
    end;
    finally thank you very much.
     
  6. vcorp
    Offline

    vcorp DF Junior

    That was awesome!
    Happy coding with delphi and thanks for sharing your final solution.
     
    Bravesaw likes this.
  7. Tony D
    Offline

    Tony DTony D is a Featured Member DF Member DF Donator

    A progress bar is one of those things you might want to consider sub-classing and in the subclass using a TThread or the PPL to make it run a bit smoother on a separate thread and that way it will not interfere with the UI main thread. Just a thought
     
    Bravesaw likes this.
  8. Bravesaw
    Online

    Bravesaw DF Junior

    First : Thanks very much Mr: Tony D
    Finally: can you Please add your Thread code here ... So that everyone can benefit from it ...:)
     
  9. Tony D
    Offline

    Tony DTony D is a Featured Member DF Member DF Donator

    Never actually done it, but I'll have go at it in my lunch hour today and post it ;-)
     
    Bravesaw likes this.
  10. Koru
    Online

    Koru DF Member

    Hi all,
    that thread code, in some momment will have to access the main UI, so I'm not sure it will help in some way.
    If the progress bar has to be updated due to another UI event (and there are not another complex calculations here), I'll not do any thread to manage it.
    If there are too many 'update' events and you want to reduce them (imagine you have a lot of images loading at the same time), then you could filter them to reduce usage. You can filter them in different ways. If this filter is complex, and one of the criterias is a timeout) then yes you could use a thread for it (or a timer if threads are a nightmare for you ;) )
     
    Bravesaw likes this.

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block