Board index » cppbuilder » Problem in using forms with two constructors.

Problem in using forms with two constructors.

Hello!
Suddenly I have found interesting bug in BCB4.
I attempted to create form with two constructor like this:

__fastcall TfmEdit1::TfmEdit1(TComponent* Owner)
 : TForm(Owner)
{

Quote
}

__fastcall TfmEdit1::TfmEdit1(TComponent* Owner, const int i)
 : TForm(Owner)
{
    Id = i;

Quote
}

Then I attempted to instantinate  the variable like this:

fmEdi1 = new TfmEdit1(this,10);

In result I have received loop until "Stack overflow" message. Please,
if anybody knows solutions, help me.

Andrew.

 

Re:Problem in using forms with two constructors.


: Andrey Smagin <s...@grandfs.ru> wrote:

Quote
>Suddenly I have found interesting bug in BCB4.

It is not a bug, just missing information.

Quote
>__fastcall TfmEdit1::TfmEdit1(TComponent* Owner, const int i)

There already is a constructor with that signature. Please use a different
signature, for instance

  __fastcall TfmEdit1::TfmEdit1(const int i, TComponent* Owner)

--
Stefan Hoffmeister (TeamB)     http://www.econos.de/
Please do apply judgement when sending email.

Re:Problem in using forms with two constructors.


Quote
> There already is a constructor with that signature.

I know that TCustomForm has a constructor with the (TComponent*, int)
signature, but each form is a sub-class of TForm which is a subclass of
TCustomForm, and constructors are not inherited.  So, why does declaring
a constructor with the same signature as a grand-parent's class cause a
problem?

Now that I've asked the question, let me guess the answer: the
implementation of the form streaming sub-system uses the special (dummy)
constructor.  Declaring a constructor in a user-defined form with the
same signature causes the sub-system to call the wrong constructor when
the form resource is read.  

If this is what happens, then I'd have to say that the problem that
occurs by declaring the special constructor is a limitation of BCB.

-chad

Other Threads