Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 540
  • Last Modified:

Break in FOR - Loop

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
omsec
Asked:
omsec
1 Solution
 
vladikaCommented:
Try it

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

:-)

0
 
omsecAuthor Commented:
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
 
ZifNabCommented:
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
Technology Partners: 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!

 
rickpetCommented:
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
 
rickpetCommented:
oops...Wrong
Case (Sender as Button).Tag of

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

Rick

0
 
omsecAuthor Commented:
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
 
omsecAuthor Commented:
Please give me a bit more detailed Information about how the FOR-Loop should look like. Thanks
0
 
333Commented:
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
 
rickpetCommented:
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
 
omsecAuthor Commented:
sorry for my late reply. i messed out how this can be done now, thanx for  showing me the way :)
0

Featured Post

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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now