Recent

Author Topic: Can an event triggered in a modal form be detected also by its main form ?  (Read 2732 times)

Relativity

  • Full Member
  • ***
  • Posts: 103
I have a main form and a second modal form, which is open upon user's request from the main one.
So the unit of the main form has the "use" clause of the unit of the second form and it is the main form that loads certain data in the second form before showing it.

I would like that when the user clicks a button or so in the second form, the second form sells a request to the main form to update the data to show.
What I need is a kind of event that breaks out in the second form, but which is also detected by the main father form.

Is anything like this possible ?
"How'm I gonna get through?"
  -- Pet Shop Boys

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: Can an event triggered in a modal form be detected also by its main form ?
« Reply #1 on: September 26, 2016, 05:10:38 pm »
Why make it difficult when you can do it more simple.
i presume that you know what you have changed.
Open your second as a always on top and as ShowModal.


When close your second one just update/refresh your frist.
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

Fungus

  • Sr. Member
  • ****
  • Posts: 353
Re: Can an event triggered in a modal form be detected also by its main form ?
« Reply #2 on: September 26, 2016, 05:57:22 pm »
Why not call the parent form directly? You can simply add the parent forms unit to the uses clause in the modal forms implementation (to prevent circular reference) and access the parent forms public methods and variables.

Bart

  • Hero Member
  • *****
  • Posts: 5288
    • Bart en Mariska's Webstek
Re: Can an event triggered in a modal form be detected also by its main form ?
« Reply #3 on: September 26, 2016, 06:21:29 pm »
Yes you can.
A common example is the use of a modaldialog form with an "Apply" button.
Clicking on the Apply button will generate an event, and an event handler for this event can be on the calling form.

Bart

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Can an event triggered in a modal form be detected also by its main form ?
« Reply #4 on: September 26, 2016, 06:58:49 pm »
You can also achieve this via a property of the main form, without using a custom event. See the attached simple (pointless) example.
« Last Edit: September 26, 2016, 07:02:54 pm by howardpc »

Relativity

  • Full Member
  • ***
  • Posts: 103
Re: Can an event triggered in a modal form be detected also by its main form ?
« Reply #5 on: September 28, 2016, 01:22:27 pm »
Thanks to everybody.
I've picked Fungus's solution. It is perfect.
Thanks also to howardpc: in his example I could exactly see, where the "uses" clause in the implementation must be put.
The problem is solved.
"How'm I gonna get through?"
  -- Pet Shop Boys

 

TinyPortal © 2005-2018