Wait to click on the button !

I have the folowing situation. I have code with while looop which call 1 procedure. In this procedure i need to put code that will wait for the user to click on the button and then continue working.

Example

while 1 do
call procedure

procedure begin
somthing
somthing
wait for user to click on the button and continue
somthing
end
65zgtre45rrAsked:
Who is Participating?
 
Scay7Commented:
for that procedure start rather use a timer1 to loop the get procedure
then in get create a loop with "repeat" and application.processmessages, this
will allow the user to click the button thats on the same form in order for him to continue

example below
etc...


var carryon : boolean;  //global var

procedure TForm1.FormCreate(Sender: TObject);
begin
carryon := false;
end

procedure Get(var1, var2 : string);
begin
  do somthing
  do somthing
    repeat  
      if carryon = true then
      begin
      //wait use to click on the button which is on the same form
      end;
    application.processmessages;
    until carryon = true;  //now that carryon = true program can finish...
  do somthing
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
Get(var1, var2);
end;


procedure TfrmWork.Button1Click(Sender: TObject);
begin
carryon := true;
// this is the on button click code
end;

peace Scay7
0
 
2266180Commented:
there is evry little information and too many solutions to point you in teh right direction for your situation. so here are a few solutions:
- use a modal form that only has one or 2 buttons (like ok, cancel) and do a showmodal instead of the "wait for user to click on the button and continue"
- if the button doesn't have an event associated then:
write an onclick event handler in it set the variable isok to true;
assign the new onclick event handler to te buttons onclick event
(the above is done only once) now comes the while 1 do
set a variable isok to false;
instead of "wait for user to click on the button and continue" do:
while not isok do
begin
  application.processmessages;
  sleep(50);
end;
while 1 do is now finished
set the onclick event of the button to nil
- if the button has an event handler, do as above, but:
first save the event handler to say buttonclicksaved
after the while not isok do
if assigned(buttonclicksaved) then
  buttonclicksaved(this);// to call the saved event handler
at finish, instead of settting the button event to nil, set it to buttonclicksaved
0
 
geobulCommented:
Hello,

>wait for user to click on the button and continue
=
ShowMessage('Click me');


If you're talking about a specific button somewhere on a form, give us a bit more details:
- what calls "while 1 do ..."?
- is it a member of the same form where the button is. Or it is a part of a standalone procedure?
- can the second procedure be a method of that form also?
- there might be more questions later on...

Regards, Geo
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
65zgtre45rrAuthor Commented:
All is on the same form, somthing like this: Start procedure will loop and in every loop will call Get, Get will do somthing then wait user to click on Button1 and then do somthing again.

procedure Get(var1, var2 : string);
begin
  do somthing
  do somthing
  wait use to click on the button which is on the same form
  do somthing
end;


procedure TfrmWork.Button1Click(Sender: TObject);
begin

 this is the on button click code
end;


procedure Start(var1, var2 : string);
begin
while 1 do
Get(var1, var);

end;
0
 
Scay7Commented:
Sorry forgot to mention that when the program is created the timer1 is enabled meaing every second (you can change this time) it will call the GET procedure and stay inside the loop until users interaction is clicked and the finish

Other wise

when putting the timer1 on the form make is enabled property disabled.
the use someother button to enabled the timer and start the get process

peace Scay7
0
 
65zgtre45rrAuthor Commented:
//wait use to click on the button which is on the same form

what do i need to put insted of this ?
0
 
65zgtre45rrAuthor Commented:
Problem solved
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.