Board index » cppbuilder » How to destroy a dynamically created form

How to destroy a dynamically created form

I am trying to destroy dynamically created forms based on various user interactions. To do this, I am storing the pointer to each form in a TList and then trying to delete the TList objects one at a time when needed. The following are snippets of code for creation and deletion:

Application start code contains:

    OpenForms=new TList();

Form Creation code contains:

      newForm=new TForm(Owner);
      OpenForms->Add(newForm);

Form Deletion code contains:

  int i;
  TForm *fm;
  for(i=0;i<OpenForms->Count;i++)
  { fm=(TForm*)OpenForms->Items[i];
    fm->OnClose=NULL; //remove previous OnClose routines
    delete fm;
  }
  OpenForms->Clear();

I am receiving Access Violation errors. Does anybody have any ideas?

 

Re:How to destroy a dynamically created form


"Remy Lebeau [TeamB]" <gambi...@gte.net> wrote:

Quote
>It would help if you indicated WHERE it was throwing the exception.

>Gambit

>"Brian" <brian.plot...@fnc.fujitsu.com> wrote in message
>news:3c890f66$1_2@dnews...

>> I am receiving Access Violation errors. Does anybody have any ideas?

In the try..catch loop of WinMain.

Re:How to destroy a dynamically created form


It would help if you indicated WHERE it was throwing the exception.

Gambit

Quote
"Brian" <brian.plot...@fnc.fujitsu.com> wrote in message

news:3c890f66$1_2@dnews...
Quote
> I am receiving Access Violation errors. Does anybody have any ideas?

Re:How to destroy a dynamically created form


Yes, sorry for not making that clearer before.  Use the de{*word*81} to narrow
the crash to the actual line that is causing it, if you can.

Gambit

Quote
"Ryan Wade" <rw...@firstam.com> wrote in message news:3c8934ea$1_1@dnews...
> He means where in this block is it crashing

<snip>

Re:How to destroy a dynamically created form


He means where in this block is it crashing

  int i;
  TForm *fm;
  for(i=0;i<OpenForms->Count;i++)
  { fm=(TForm*)OpenForms->Items[i];
    fm->OnClose=NULL; //remove previous OnClose routines
    delete fm;
  }
  OpenForms->Clear();

Quote
"Brian" <brian.plot...@fnc.fujitsu.com> wrote in message

news:3c891da7$1_1@dnews...
Quote

> "Remy Lebeau [TeamB]" <gambi...@gte.net> wrote:
> >It would help if you indicated WHERE it was throwing the exception.

> >Gambit

> >"Brian" <brian.plot...@fnc.fujitsu.com> wrote in message
> >news:3c890f66$1_2@dnews...

> >> I am receiving Access Violation errors. Does anybody have any ideas?

> In the try..catch loop of WinMain.

Other Threads