[lazarus] Get button state
Michael Van Canneyt
michael.vancanneyt at wisa.be
Tue Dec 16 09:52:05 EST 2003
On Tue, 16 Dec 2003, Sebastian Kraft wrote:
> 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.
More information about the Lazarus
mailing list