Recent

Author Topic: Problem set button to enabled = false  (Read 5227 times)

MaartenJB

  • Full Member
  • ***
  • Posts: 119
Problem set button to enabled = false
« on: November 08, 2011, 05:03:25 pm »
Hi,

I've got a problem with setting a button to status enabled:= false. The button on the form does not refresh properly after the ProcessMessages command. This is the example code, two buttons on the form, button1 disables button2:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  Button2.Enabled := False;

  Application.ProcessMessages;
  sleep(2000); // for example 2 seconds
end;

The strange thing is that it will work with the sender button "Button1".

Thanks in advance!

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Problem set button to enabled = false
« Reply #1 on: November 08, 2011, 05:22:47 pm »
Seems strange indeed.

This is 1 kind of workaround that seems to work... don't ask why  :P
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var n: integer;
begin
  Button2.Enabled := False;
  for n:=1 to 40 do begin
    Application.ProcessMessages;
    sleep(50);
  end;
end;

MaartenJB

  • Full Member
  • ***
  • Posts: 119
Re: Problem set button to enabled = false
« Reply #2 on: November 09, 2011, 09:24:02 am »
strange :-)

This does work too:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  Button2.Enabled := False;

  Sleep(200);
  Application.ProcessMessages;

  sleep(2000);
end;

When you change the first sleep to "90", the button goes half way trough the button animation.


 

TinyPortal © 2005-2018