Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Break in FOR - Loop

Posted on 1998-07-10
10
Medium Priority
?
538 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 180 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

604 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