Board index » cppbuilder » Changing ancestor of custom Form...

Changing ancestor of custom Form...

Could you post some code ?

Carina Rodriguez <> wrote in message
> Hi,

> I created a form BASEFORM which I use as a base class for derived form
> FormMain. Then I discovered that on Application->Terminate() (with Fast
> exception prologs = ON, under C++ options), I always get message "access

> violation at 0x77ff889ef : write of address ....etc..".
> This happens after WinMain() leaves try-catch loop and returns(0) (the
> last command of WinMain)
> I guess it has something to do with destruction of FormMain (because
> un-handled exception has been throw at that moment?).
> Now I would like to change ancestor of FormMain to TForm, but I can not
> (even if I remove #include "BASEFORM.h" from my heder file, it gets
> written automaticaly by BCB when I do "save").
> How to change ancestor when the form already exists ?

> Thanks in advance, and best regards,

> Carina


Re:Changing ancestor of custom Form...

Ilian Iliev wrote:

Could you post some code ?

Hi Ilian,

This is portion from header file :

#include "BASEFORM.h"
class TFormMain : public TMyBaseForm
__published: // IDE-managed Components
    // some IDE stuff

private: // User declarations
public:  // User declarations
    __fastcall TFormMain(TComponent* Owner);


extern PACKAGE TFormMain *FormMain;

and portion from .cpp file :
#include "WinGUI.h"
#pragma resource "*.dfm"
#pragma package(smart_init)
#pragma link "BASEFORM"

TFormMain *FormMain;
__fastcall TFormMain::TFormMain(TComponent* Owner)
    : TMyBaseForm(Owner)
Application->OnMessage = AppMessage;




Please note that I tried already to change :
    class TFormMain : public TMyBaseForm    (in header file) to
    class TFormMain : public TForm

and constructor in .cpp file :
    __fastcall TFormMain::TFormMain(TComponent* Owner)
        : TMyBaseForm(Owner)
change into
    __fastcall TFormMain::TFormMain(TComponent* Owner)
        : TForm(Owner)

but it did not work. Why ?
Thank in advance,


Re:Changing ancestor of custom Form...

Hi, Carina!

There are a number of possibilities as to the source of the AV, but form
inheritance per se isn't one of them. More likely, you're OnMessage
handler is getting and dispatching messages after something it needs has
already been destroyed.

Perhaps you can post your OnMessage handler. Alternatively, have the
form destructor set Application->OnMessage to NULL.

If that doesn't work, you can change form inheritance by editing the
header file outside the context of the IDE. Then, in the IDE open the
.dfm without a project open and change the code there from "inherited"
to "object" with the appropriate classes (it's a little hard to
describe). Back up everything before you do this.

Finally, edit your project source with notepad and remove the USEFORM
for the ancestor.

But I think you will do best to find your problem than to abandon form
inheritance because of it.

Mark Cashman (TeamB - C++ Builder), creator of The Temp{*word*203}Doorway at
- Original digital art, writing, music and more -
C++ Builder / JBuilder Tips and The C++ Builder Programmer's Webring
(Join us!)

Re:Changing ancestor of custom Form...

thanks Mark (and sorry for cross-posting...was not sure which category the
question was..)

I will first try checking for already deleted objects, and will post results
of my research...thanks again.

Other Threads