Solved

Screen not updating/hourglass

Posted on 2002-06-20
9
1,342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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