Solved

Screen not updating/hourglass

Posted on 2002-06-20
9
1,323 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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