Board index » cppbuilder » Forcing Modal to close

Forcing Modal to close


2006-04-12 10:17:01 PM
cppbuilder46
Hi,
i want to close all forms that are parent of my main form
for(int i=0;i<this->MDIChildCount;i++)
{
this->MDIChildren[i]->Close();
}
i close all the forms when a certain timer reach a value
and "locks" my aplication showing only one modal asking the
user to insert pass to "unlock" aplication..
works ok except when the aplication is locked and a modal
is showing at the moment, because when user unlocks the aplication
it starts running the code next to the modal that doesnt
exists anymore
(...)
void __fastcall TvendasFORM::BguardarClick(TObject *Sender)
{
(...)
TinfoanexaFORM *infa = new TinfoanexaFORM(this);
Quote
>>if(infa->ShowModal() == mrOk)
this->verifica_idrecibo(infa->idmov);
(..)
doing a break poing on '>>>' i can see it trys to call the
function inside the IF, Firing access memory erros
thx in advanced
 
 

Re:Forcing Modal to close

Daniel F wrote:
Quote
for(int i=0;i<this->MDIChildCount;i++)
{
this->MDIChildren[i]->Close();
}
Mostly you can better do that backwards: start with the last form and then loop
until the firstone. The MDIChildren array might be rearranged.
Quote
i close all the forms when a certain timer reach a value
and "locks" my aplication showing only one modal ...
Are you doing that in the timer eventhandler ?
Quote
works ok except when the aplication is locked and a modal
is showing at the moment,
Don't understand. Are you trying to 'lock' the application a second time ?
Is there another modal form besides the password form ?
Quote
because when user unlocks the aplication
it starts running the code next to the modal that doesnt
exists anymore
(...)
void __fastcall TvendasFORM::BguardarClick(TObject *Sender)
Is this instance of TvendasForm the mainform ?
Quote
doing a break poing on '>>>'
Think that you should indicate that line in a different way.
Quote
i can see it trys to call the
function inside the IF, Firing access memory erros
What is 'IF' ?
Please clarify.
Hans.
 

Re:Forcing Modal to close

"Daniel F" < XXXX@XXXXX.COM >wrote in message
Quote
i want to close all forms that are parent of my main form

for(int i=0;i<this->MDIChildCount;i++)
{
this->MDIChildren[i]->Close();
}
You should be looping backwards:
for(int i = MDIChildCount-1; x>=0; --i)
{
MDIChildren[i]->Close();
}
Quote
works ok except when the aplication is locked and a modal
is showing at the moment, because when user unlocks the
aplication it starts running the code next to the modal that
doesnt exists anymore
How does your lock prevent the already-running code from continuing its work
in the first place?
Quote
TinfoanexaFORM *infa = new TinfoanexaFORM(this);

>>>if(infa->ShowModal() == mrOk)
this->verifica_idrecibo(infa->idmov);

(..)

doing a break poing on '>>>' i can see it trys to call the
function inside the IF, Firing access memory erros
For that to happen suggests, you would have to be freeing your child forms
when they are closed. Are you actually doing that? Your code design is
dependant on the child forms sticking around after they are closed, so you
should not be freeing them at all when they close.
Gambit
 

{smallsort}

Re:Forcing Modal to close

thx for your response
Quote
You should be looping backwards:

for(int i = MDIChildCount-1; x>=0; --i)
{
MDIChildren[i]->Close();
}
same thing it seems...
Quote
>works ok except when the application is locked and a modal
>is showing at the moment, because when user unlocks the
>application it starts running the code next to the modal that
>doesnt exists anymore

How does your lock prevent the already-running code from continuing its work
in the first place?
i was hopping i could force them to stop since the following
errors come from trying to execute code of objects that no
longer exist (firing access memory errors)
Quote
>TinfoanexaFORM *infa = new TinfoanexaFORM(this);
>
>>>>if(infa->ShowModal() == mrOk)
>this->verifica_idrecibo(infa->idmov);
>

For that to happen suggests, you would have to be freeing
your child forms
when they are closed. Are you actually doing that? Your
code design is
Dependant on the child forms sticking around after they
are closed,
iam freeing the forms onclose event
so you
Quote
should not be freeing them at all when they close.
i need to free the forms so they dont stick around on
the fsMDIForm
in conclusion:
if i have only fsMDIChild forms i can close them with no
problem, when user "unlocks" application all goes smooth,
if there is a modal form showing at the moment application
is "locked" when user "unlocks" it it shows a considerable
number of access memory errors, since the CPU trys to
execute the code next to the modal call..
(...)
if(infa->ShowModal() == mrOk)
Quote
>this->verifica_idrecibo(infa->idmov);
(...)
(sry iam having trouble finding the words to express
my self clear :S ) note that this modal was called
by one of the fsMDIChild that is now closed and freed.
Thx once again
Daniel F
 

Re:Forcing Modal to close

"Daniel F" < XXXX@XXXXX.COM >wrote in message
Quote
iam freeing the forms onclose event

i need to free the forms so they dont stick around on the fsMDIForm
Then you need to change your code design. Like I told you earlier, your
current code depends on the children NOT being freed when they close. That
is why you are getting AVs - you are trying to access children that no
longer exists. You need to stop doing that completely, or else delay the
freeing until after you are absolutely sure that the children will not be
accessed anymore,. You can have the OnClose event hide the children when
they close so that the user doesn't see them anymore in the UI, but they
will still be in memory for your code to continue accessing them.
Or else simply dont allow the user to lock the application at all while any
modal forms are still active. You can loop through the TScreen::Forms array
looking for forms that have the fsModal flag in their FormState property.
Quote
note that this modal was called by one of the fsMDIChild that is
now closed and freed.
Then why not simply have the child close the modal form that it opened
before allowing itself to fully close?
Gambit