Solved

Screen not updating/hourglass

Posted on 2002-06-20
9
1,295 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 2

Expert Comment

by:Griffon
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 6

Accepted Solution

by:
DrDelphi earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
>Is this feature available in Delphi 3 Pro?

no
0
 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
No, 'fraid not...Sorry.
0
 
LVL 2

Expert Comment

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now