Solved

Screen not updating/hourglass

Posted on 2002-06-20
9
1,313 Views
Last Modified: 2008-02-01
Hi...
   My app is reading and processing a large file and sometimes won't update my progress gauge (code below). Also, the cursor will change to an hourglass (but when I move to other applications I have running, the cursor returns to a normal arrow). My app doesn't lock while this is going in however, it still runs fine...just my status gauge won't update while it's running.

The funny thing is that this behaviour doesn't happen all the time - sometimes I'll run the app and the progress gauge will update fine and the cursor doesn't turn to an hourglass. Very strange.

Here's my code (my gauge should refresh every 10 records read):


repeat
    if multitask then Application.ProcessMessages;
    buf:='';
    blockread(fromfile, buf, 1, numread);
    recsread:=recsread + 1;
   
    for z:=0 to 49151 do
    begin
      if ((ord(buf[z])>= 0) and (ord(buf[z]) <= 31)) or
         ((ord(buf[z])>= 127) and (ord(buf[z]) <= 255))  then
      begin
         if bigstring <> '' then find_valid;
      end
      else
      begin
        bigstring:=concat(bigstring, buf[z]);
        if length(bigstring) = 255 then find_valid;
      end;
    end;

    bytes_processed:=bytes_processed + 49152;
    if recsread mod 10 = 0 then
    begin
      hperc:=calc_status(totsizeoffile, bytes_processed);
      gauge14.progress:=hperc;
      Form1.update;
    end;

  until EOF(fromfile);


I'm using Windows XP Home, and Delphi 3 Pro.

Thanks
   Shawn

0
Comment
Question by:aztec
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7097787
a guess

...
bytes_processed:=bytes_processed + 49152;
   if recsread mod 10 = 0 then
   begin
     hperc:=calc_status(totsizeoffile, bytes_processed);
     gauge14.progress:=hperc;
     Form1.update;
     Application.processmessages; //add this line here
   end;
...


meikl ;-)
0
 

Author Comment

by:aztec
ID: 7097794
yes, but even with no "Application.processmesages" , I *still* sometimes get my progress bar updating...with good cursor. (ie. my 'multitask' boolean var is set to false)
0
 
LVL 2

Expert Comment

by:333
ID: 7098147
actually, Form.Update does nothing special, it only sends WM_PAINT message. if you don't call Application.ProcessMessages during tight loop, chances that your form will handle WM_PAINT are very small.
just guessing, but your form sometimes may be updated because of blocking in BlockRead. if BlockRead blocks, your loop stops and mybe windows is able to call your WindowProc. as i said, it's just a guess :) you need to use Application.ProcessMessages
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 2

Expert Comment

by:Griffon
ID: 7098679
I would use a refresh on the form and as for the cursor why not actually set the cursor to hourglass at the begining of your process and then back after that way it will show the user that it is occupied.

Im assuming delphi3 has the:

Screen.Cursor := crHourGlass;

to set back

Screen.Cursor := crDefault;

I would think that the gauge is updating but the screen is not refreshing so even though the gauge is working you are not seeing it.

form.refresh .. is what I use and it seems to work.

also try and make sure that if it is recording % it will only try and update once for each % etc. This should minimalise the form flicker.
0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 50 total points
ID: 7099587
Put the Application.ProcessMessages in the loop (as previuosly mentioned), and set the set the Form's DoubleBuffered property to true to prevent flicker. This can be done in the Form.Create:
i,e:
 

Self.DoubleBuffered:=True;


the alternative is to launch a seperate thread to handle this processing.


Good luck!!
0
 

Author Comment

by:aztec
ID: 7106458
DrDelphi - the 'DoubleBuffered' statement gives me a compile error. Is this feature available in Delphi 3 Pro?

Thanks
   Shawn
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7106478
>Is this feature available in Delphi 3 Pro?

no
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7107506
No, 'fraid not...Sorry.
0
 
LVL 2

Expert Comment

by:mikepj
ID: 7123795
You can minimize flicker by forcing update only for the progress bar itself; no need to refresh the whole form.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Virtuailstring tree compare node issue 14 117
Comparing dates in Delphi. Greater than/ Less than 3 155
Delphi XE10 Round Image 2 129
Strange behavior when a form is closed 6 58
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question