Sign in Join

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

Mailing lists / lazarus / 2003-12

Get button state

6 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

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

Michael Van Canneyt
to Sebastian Kraft: I have a window with 2 buttons. One Start and one Stop. When clicking on start the…
Sebastian Kraft wrote 17 lines
Hi all, I have a window with 2 buttons. One Start and one Stop. When clicking on start the program begins to write some lines to the commandline. How can I find out when the button stop is pressed? Seems the event isn't handled when the Program is still hanging in the start-button event... Should look kind of that... procedure TTestwin.startClicked(Sender: TObject); begin repeat writeln('xxx') until "button stop pressed"; end; But I've no idea who to build that in Pascal code... Can anyone help?

In the form class declaration, Introduce a boolean variable FStopped:

Private
  FStopped : Boolean;

The start button onclick handler works as follows:

procedure TTestwin.StartClicked(Sender: TObject);
begin
 FStopped:=False;
 repeat
    writeln('xxx');
    Application.ProcessMessages; // Process pending messages.
 until FStopped;
end;

The stop button onclick handler works as follows:

procedure TTestwin.StopClicked(Sender: TObject);
begin
  FStopped:=True;
end;

The most important part is the

  Application.ProcessMessages;

This makes sure that the click on the stop button is registered.

Michael.

Reply by email

Sebastian Kraft
to Sebastian Kraft: I have a window with 2 buttons. One Start and one Stop. When clicking on start the…
Show quoted text 16 lines
You have to give the LCL event queue some processing time. procedure TTestwin.startClicked(Sender: TObject); begin ButtonStopPressed:=false; repeat writeln('xxx'); Application.ProcessMessages; until ButtonStopPressed; end; procedure TTestwin.stopClicked(Sender: TObject); begin ButtonStopPressed:=true; end;

Great thanks!!
That solved it...

But I still have another problem as you can see in the other post ;-) Documentation is not very helpful yet....

Sebastian

Reply by email

Sebastian Kraft

Hi all,

I have a window with 2 buttons. One Start and one Stop. When clicking on start the program begins to write some lines to the commandline. How can I find out when the button stop is pressed? Seems the event isn't handled when the Program is still hanging in the start-button event...

Should look kind of that...

procedure TTestwin.startClicked(Sender: TObject);
begin
 repeat writeln('xxx') until "button stop pressed";
end;

But I've no idea who to build that in Pascal code...

Can anyone help?

Sebastian

Reply by email

Mattias Gaertner
to Sebastian Kraft
Show quoted text 17 lines
Hi all, I have a window with 2 buttons. One Start and one Stop. When clicking on start the program begins to write some lines to the commandline. How can I find out when the button stop is pressed? Seems the event isn't handled when the Program is still hanging in the start-button event... Should look kind of that... procedure TTestwin.startClicked(Sender: TObject); begin repeat writeln('xxx') until "button stop pressed"; end; But I've no idea who to build that in Pascal code... Can anyone help?

You have to give the LCL event queue some processing time.

procedure TTestwin.startClicked(Sender: TObject);
begin
  ButtonStopPressed:=false;
  repeat
    writeln('xxx');
    Application.ProcessMessages;
  until ButtonStopPressed;
end;
procedure TTestwin.stopClicked(Sender: TObject);
begin
  ButtonStopPressed:=true;
end;

OR:
Put your writeln in an Application.OnIdle event.

Mattias

Reply by email

Michael A. Hess
to Sebastian Kraft: I have a window with 2 buttons. One Start and one Stop. When clicking on start the…
Hmmmm. Let's see. Michael wrote 15 lines
procedure TTestwin.StartClicked(Sender: TObject); begin FStopped:=False; repeat writeln('xxx'); Application.ProcessMessages; // Process pending messages. until FStopped; end; procedure TTestwin.StopClicked(Sender: TObject); begin FStopped:=True; end;
and Mattias wrote 13 lines
procedure TTestwin.startClicked(Sender: TObject); begin ButtonStopPressed:=false; repeat writeln('xxx'); Application.ProcessMessages; until ButtonStopPressed; end; procedure TTestwin.stopClicked(Sender: TObject); begin ButtonStopPressed:=true; end;

Clearly a serious Intel. Prop. issues here. Since Mattias was date posted first I guess Michael MUST of copied his code and just changed it a little to appear that it was different but clearly he copied it.

Hee hee hee. ;-)

This was such a great example of why some of the SCO stuff is so much hog wash. Somethings are just written some ways and that is that.

Just struck me funny.

==== Programming my first best destiny! ==== Michael A. Hess Miracle Concepts, Inc. http://www.miraclec.com Phone: 570-388-2211 Fax: 570-388-6101

Reply by email

Marco van de Voort
to Michael A. Hess
Show quoted text 10 lines
> begin > ButtonStopPressed:=true; > end; Clearly a serious Intel. Prop. issues here. Since Mattias was date posted first I guess Michael MUST of copied his code and just changed it a little to appear that it was different but clearly he copied it. Hee hee hee. ;-)

/me bets on linux vs windows.

Michael, linux user, having set hwtime to UTC, and posting in UTC to avoid local time issues.

Reply by email