?
Solved

Problem about loops

Posted on 2000-01-01
6
Medium Priority
?
140 Views
Last Modified: 2010-04-06
Hi,  I have the following code:
procedure TForm1.Button1Click(Sender: TObject);
var
   i   :integer;
begin
......
     for i:=1 to 100 do
     begin
          temp:=i;   (temp is a global var)
          Form1.SomethingDone;   (this will use temp somewhere)
     end;
......
end;

procedure TForm1.SomethingDone;
begin
......
     if something=1 then ...
     if something=2 then ...
     if something=3 then ...
......
     if something=10 then ...
end;
My question is that: AFTER the execution of somethingdone, it will be called once again if something<>10 (ie. itself is an event)
But the problem arises, after somethingdone is executed once ONLY, the for loop in button1click continues executing immediately.  How can I make the for loop "wait" and continue executing until SomethingDone has been executed 10 times? (The var something will increase by 1 each time)
Please dont suggest me to include the code in somethingdone in the button1click, since somethingdone is actually a component's event.
Thanks!!
0
Comment
Question by:nyt
  • 3
  • 3
6 Comments
 

Author Comment

by:nyt
ID: 2318125
Edited text of question.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2318164
hi,
do you want something like this:
Regards Barry

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  temp : integer = 0;
implementation

{$R *.DFM}
procedure something;
begin
showmessage('doing it '+inttostr(temp));
end;

procedure TForm1.Button1Click(Sender: TObject);
var
i ,ii: integer;
begin
for i := 0 to 100 do begin
   for ii := 0 to 9 do begin
    something;
    inc(temp);
   end;
   temp := 0;
  end;

end;

end.
0
 

Author Comment

by:nyt
ID: 2318226
Sorry,
Actually, something is the procedure being called when the procedure something itself has been ended (Event of an component)
When temp is changing, the procedure something will do different things.  Of course, the procedure something is not simply a inc(temp)...it has more than 50 lines...
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
ID: 2318236
what about adding a global boolean and inside the loop
do something like :

for i ...
begin
 MyBoolean := True;
  something;
   Repeat Aplication.Processmessages
  until
 MyBoolean = false;
end;

back to loop

and inside or after components event set myboolan := false
0
 

Author Comment

by:nyt
ID: 2318256
Thank you!  It does what I need.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2318273
:-) glad to hear it works
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question