Recent

Author Topic: How do I make a procedure in one form wait for a value from another form?  (Read 1121 times)

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
I created two forms.  I click in form1 to get two numbers from form2.


I start with this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormActivate(Sender: TObject);
  2. begin
  3.   Form2.Enabled:=FALSE;
  4.   Form2.Visible:=FALSE;
  5. end; // End TForm1.FormActivate(Sender: TObject)

So, just to make sure, In form1 I hide and disable form2 during form1 activation.


In form1 I have a TListBox with the following:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListBox1Click(Sender: TObject);
  2.         Form2.Enabled:=TRUE;
  3.         Form2.Visible:=TRUE;
  4.  
I enable and make visible form2 which has a TSpinEdit.
The very next line is:
Code: Pascal  [Select][+][-]
  1.     While Form2.Visible Do;
My intent is for form 1 to stop and wait (by looping around) for me to spin to the correct number in form2 and then in form2 I have a procedure:
Code: Pascal  [Select][+][-]
  1. procedure TForm2.Button1Click(Sender: TObject);
  2. begin
  3.   Number := SpinList1.Value+2;
  4.   Form2.Visible:=FALSE;
  5. end;
  Now it isn't visible so it's false and the procedure in form1 should continue.  But not before I click the button in form2.


Now, the problem is that I think the While loop is running, but the procedure continues with the code AFTER the While loop even though form2 is still visible.  As long as Form2 is visible, the While loop should be...
...
Looping!  And not continuing past the While loop.

Shouldn't it?

Or is there something that makes
Code: Pascal  [Select][+][-]
  1. Form2.Visible
false even though during runtime, I can see it!
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

SudoKai

  • Newbie
  • Posts: 6
    • SudoKai
Code: Pascal  [Select][+][-]
  1.  //Form2.Visible := True;
  2.  Form2.ShowModal;
  3.  
  4.  //Form2.Visible := False;
  5.  Form2.Close;

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Code: Pascal  [Select][+][-]
  1.  //Form2.Visible := True;
  2.  Form2.ShowModal;
  3.  
  4.  //Form2.Visible := False;
  5.  Form2.Close;

I'm a beginner.  I do not understand your reply.
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

SudoKai

  • Newbie
  • Posts: 6
    • SudoKai
To make a form visible and wait for a response you can use ShowModal

To close (or hide) a form you can use Close


Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListBox1Click(Sender: TObject);
  2.         Form2.ShowModal;

Code: Pascal  [Select][+][-]
  1. procedure TForm2.Button1Click(Sender: TObject);
  2. begin
  3.   Number := SpinList1.Value+2;
  4.   Form2.Close;
  5. end;

MarkMLl

  • Hero Member
  • *****
  • Posts: 6647
This is a bit of arcane terminology that goes back to Xerox PARC in the 70s. A modal form is one that has to be interacted with and closed before its caller continues, basically like a custom dialog(ue) box.

MarkMLl


MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
To make a form visible and wait for a response you can use ShowModal

To close (or hide) a form you can use Close


Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListBox1Click(Sender: TObject);
  2.         Form2.ShowModal;

Code: Pascal  [Select][+][-]
  1. procedure TForm2.Button1Click(Sender: TObject);
  2. begin
  3.   Number := SpinList1.Value+2;
  4.   Form2.Close;
  5. end;

Thanks!  this worked!
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

 

TinyPortal © 2005-2018