Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-03

Newbie

7 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Milan Baša

Hi all.
I have this little code, but there is something i dont understand. I have form with components progressbar, statictext, edit, stringgrid, spinedit +button.

One method:
procedure TForm1.Button1Click(Sender: TObject);
var i : smallint;
begin
      for i:=0 to 10 do
          begin
            progressbar1.Position:=i;
            statictext1.Caption:=inttostr(i);
            spinedit1.Text:=inttostr(i);
            stringgrid1.Cells[1,1]:=inttostr(i);
            edit1.Text:=inttostr(i);
            sleep(1000);
          end;
end;

Result after clicking on button:

winXP, lazarus 09.28.3:

Progressbar is working, statictext is increasing numbers but every other components are frozen til the time program stops and at this moment i can see everywhwere number 10.

PCLinuxOS 2010, 0.9.31:

I see no progress, only result 10.

What i am doing wrong?
Thank You.

Reply by email

Howard Page-Clark
to Milan Baša
Milan Ba?a wrote 10 lines
stringgrid1.Cells[1,1]:=inttostr(i); edit1.Text:=inttostr(i); sleep(1000); end; Progressbar is working, statictext is increasing numbers but every other components are frozen til the time program stops and at this moment i can see everywhwere number 10. I see no progress, only result 10.

Add Application.ProcessMessages; e. g. like this

...
edit1.Text:=inttostr(i);
Application.ProcessMessages;
sleep(1000);
...

Howard

Reply by email

DSK
to Howard Page-Clark

Howard,

>Try "for i:=0 to 10000" and comment out "//sleep .." This will fail - he's declared i as shortint

Nice catch, thanks. I never even looked but used to do exactly the same - using the smallest possible type for the task at hand ... he'll just have to change it to integer then I guess :)

DSK Posted with 1.19.1.269

Reply by email

Howard Page-Clark
to DSK
DSK wrote 8 lines
Howard, > This will fail - he's declared i as shortint Dang .. shoulda checked first ... 10,000 shouldn't fail: Smallint -32768 .. 32767

mea culpa - misread

Reply by email