Forum > Designer

SOLVED Impossible to close a modal window...

(1/8) > >>

pjtuloup:
Hello everyone... New beginner problem: I can't close a modal window.
Here's how things look: My Main form (Master) calls in its FormActivate procedure a modal window used for identification.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormActivate(Sender: TObject);begin  FormIdentif.ShowModal;end;  
In this FormIdentif form there is a "Continue" button which should close the window so that the Master file is accessible with its general menu


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TFormIdentif.Btn_ContinuerClick(Sender: TObject);begin  //Close;  //FormIdentif.Close;  //FormIdentif.ModalResult:= 1;  //FormIdentif.ModalResult:= mrOK;end; 
I tried several things which don't work: either nothing happens (using ModalResult) or the application closes (with Close)

I don't see what I'm missing... Can anyone point me in the right direction? Thanks in advance!

Thaddy:
You can't easily close a modal window from somewhere else. You close a modal Window from the modal window itself. That is by design. That does not mean it can not be done, but it should not be done.
It is a bit useless to show you how to do it since you are a beginner.
I will not show you bad practice, but someone else on this forum with less understanding of the matter will show you how to do it anyway... :o :D and he or she can count on my anger... The proverbial >:D

The easy way out for a beginner is to make the window NOT modal.

pjtuloup:
Thanks but A clarification: the procedure TFormIdentif.Btn_ContinuerClick is in the form of the modal window I want to close.

MarkMLl:

--- Quote from: pjtuloup on July 03, 2024, 09:43:50 am ---In this FormIdentif form there is a "Continue" button which should close the window so that the Master file is accessible with its general menu

--- End quote ---

Make sure that the button you've labelled "Continue" is in the context of the modal form, and is marked as having e.g. a cancel effect. Can't give a more detailed example at the moment, but would echo (perhaps more gently) Thaddy's warning that this is something that shouldn't be done from outside the form.

MarkMLl

Zvoni:
I'm probably going to invoke Thaddy's Anger, but hey...no risk no fun :D

The way i do it (No code, just "steps")

1) In your Main Form you have a var for your ModalForm
2) In your MainForm you create the ModalForm, then you ShowModal that Form --> Code-Execution in your MainForm is "stopped" as long as your ModalForm is visible (here Line 3)

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---//In TMainFormModalForm:=TModalForm.Create;ModalForm.ShowModal;ModalForm.Close;ModalForm.Free; 3) In your ModalForm you have a Button (or whatever else) to close that ModalForm. I do

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TModalForm.cmdCloseClick(Sender: TObject);Begin   Self.Close;End;procedure TModalForm.FormClose(Sender: TObject;  var CloseAction: TCloseAction);begin  CloseAction:=caHide;  //THIS ONEend;     After executing above statement, code-execution returns to your MainForm to Line 4 above

...and now i have to run and hide, so Thaddy doesn't kill me... :D

Navigation

[0] Message Index

[#] Next page

Go to full version