?
Solved

Screen not updating/hourglass

Posted on 2002-06-20
9
Medium Priority
?
1,355 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 200 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

752 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