Solved

Break in FOR - Loop

Posted on 1998-07-10
10
527 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now