Solved

Break in FOR - Loop

Posted on 1998-07-10
10
532 Views
Last Modified: 2010-04-04
Hello..

I write a converion of a DOS-Pascal program into a Delphi 3 Application. The BP7 Program waits for some Data Input, while it is running in a FOR - Loop, something like

for counter := 1 to xx do
  begin
    writeln('some text');
    readln(CharVar);
  end;

In my Delphi Program, i also need the possibility to wait, until the user entered (clicked) to choose data, and then continue the FOR-Loop. But here, I don't want to wait for a Key-Press (readkey) i want to wait until the user has clicked an element. I know there is an OnClick Event. Think, i'll use an EDIT or a LABEL where the user should click onto...

thx
0
Comment
Question by:omsec
10 Comments
 
LVL 3

Expert Comment

by:vladika
ID: 1357631
Try it

  for Counter := 1 to xx do
  begin
    writeln('so,e text');
    Application.MessageBox('Click me !!!', 'Click me !!!', 0);
  end;

:-)

0
 
LVL 2

Author Comment

by:omsec
ID: 1357632
It cant be a MessageBox. I neet the User to clock an Element which is on the form. Such as an EDIT Box. And there are 4 different, so I need to check which one was clicked
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357633
The problem is that DOS can't be easy reprogrammed under Windows. Especially the user interface. The user has a lot of freedom in windows. And making a program which act like a dos program in windows is (my opinion) not so good.

Can you give a bigger explenation of what you actually want to achieve?

Zif.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:rickpet
ID: 1357634
There is a couple of ways to do this...have one event handler for each button look for the name property or tag value(you assign the tag value see code below for an example) to see what button was clicked...

//note each button needs a tag value of 1 to 4...this is a //property of index...
//on the click event for the buttons...use the same event for
//each button...use the Object Inspector drop down list in
//the events to find the correct event...and assign it
//to the correct button

Case (Sender as Button).Tag of
 1:  Showmessage('Button1 clicked');
 2:  Showmessage('Button2 clicked');
 3:  Showmessage('Button3 clicked');
 4:  Showmessage('Button4 clicked');
end;


Also this shows how to do it with sets...if you have multiple selections...

Rick

unit unSet;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  {$M+}
  TActiveStatus = (asActive,asInactive,asManager,asNonManager);
  {$M-}
  TActiveStatusSet = set of TActiveStatus;
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    GroupBox1: TGroupBox;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  ActiveStatus: TActiveStatusSet;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  i,J: Integer;
begin
  Label1.caption := '';
  ActiveStatus := [];  //this sets our set to empty
  //note if you do it this way...each check box must have a tag value equal to
  //enumerated group TActiveStatus  i.e. asActive = 0, asInActive = 1...
  //or you could assume that each child is a Tcheckbox and use the first iteration
  //also each Checkbox must be a child of the GroupBox
  for i := 0 to GroupBox1.ControlCount -1  do    // loop through all the children of the GroupBox
    if (GroupBox1.Controls[i] is TCheckBox) and ((TCheckBox(GroupBox1.Controls[i])).Checked)then
        for j := 0 to ord(high(TActiveStatus)) do
          if (TCheckBox(GroupBox1.Controls[i]).Tag =  j) then
          begin
            ActiveStatus := ActiveStatus+[TActiveStatus(j)];
            break;  //we do not need to check the rest...because there can only be one.
          end;
{ or you could do it the boring way and just check each check box to see if they
are checked...
  if checkbox1.checked then
    ActiveStatus := ActiveStatus+[asActive];
  if checkbox2.checked then
    ActiveStatus := ActiveStatus+[asInActive];
  if checkbox3.checked then
    ActiveStatus := ActiveStatus+[asManager];
  if checkbox4.checked then
    ActiveStatus := ActiveStatus+[asNonManager];}
  if asActive in ActiveStatus then  //note you can check if a value is in a set...
    Label1.Caption := 'Active';
  if asInActive in ActiveStatus then
    Label1.Caption := Label1.Caption + 'InActive';
  if asManager in ActiveStatus then
    Label1.Caption := Label1.Caption + 'Manager';
  if asNonManager in ActiveStatus then
    Label1.Caption := Label1.Caption + 'NonManager';
{ another way to check values against a set
  if ActiveStatus = [asActive,asInActive,asManager,asNonManager] then
    Label1.Caption := 'Active,InActive,Manager,NonManager';
}
end;

end.

Rick
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1357635
oops...Wrong
Case (Sender as Button).Tag of

that should be
Case (Sender as TButton).Tag of

Rick

0
 
LVL 2

Author Comment

by:omsec
ID: 1357636
well that's much of new stuff, so i'm a lil lost. When i use the first way, with the "Case" Statement, what do i have to write, to make my FOR-Loop waiting for this event ?

for counter := 1 to MAX do
  begin
     something;
     wait_and_check_what_here;
   end;

I think it shouldn't make any problems to use an EDIT instead of a BUTTON, since the OnClick - Event is also avaiable there.
0
 
LVL 2

Author Comment

by:omsec
ID: 1357637
Please give me a bit more detailed Information about how the FOR-Loop should look like. Thanks
0
 
LVL 2

Accepted Solution

by:
333 earned 60 total points
ID: 1357638
const
  max=3;
var
  count:byte;

procedure TForm1.Edit1Click(Sender: TObject);
begin
  if count<max then begin
    {Check Edit1.Text here}
  end;
end;

procedure TForm1.Edit2Click(Sender: TObject);
begin
  if count<max then begin
    {Check Edit2.Text here}
  end;
end;

procedure TForm1.Edit3Change(Sender: TObject);
begin
  if count<max then begin
    {Check Edit3.Text here}
  end;
end;

procedure TForm1.Edit4Change(Sender: TObject);
begin
  if count<max then begin
    {Check Edit4.Text here}
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  inc(count);
  if count>max then begin
    {user has enter the values max times}
    {it's like end in for-loop}
  end
  else begin
    {clear all text in 4 Edits}
    Edit1.Text:='';
    Edit2.Text:='';
    Edit3.Text:='';
    Edit4.Text:='';
  end;
end;
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1357639
Omsec...

In windows...you don't have to sit and wait like you have to do in DOS...Your code is idle until windows sends a message to your application and your application handles the message i.e. your click event.  I really would suggest you pick up a book to explain some of this to you...I would look at Delphi Unleashed or Mastering Delphi.

Should you need to sit in a loop...because your doing calculations and you want your app to be responsive to window events then just add Application.ProcessMessages in your loop.

Rick

0
 
LVL 2

Author Comment

by:omsec
ID: 1357640
sorry for my late reply. i messed out how this can be done now, thanx for  showing me the way :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 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