Board index » cppbuilder » Stack Overflow on Form Creation

Stack Overflow on Form Creation


2004-04-09 08:23:17 AM
cppbuilder65
Hello,
I'm having trouble with adding additional constructors to forms. In most
cases, the very existence of a non-default constructor will cause a 'Stack
Overflow' error on form creation, even if the default constructor is called.
From the C++ Builder documentation I understand this could happen from
excessive recursiveness or very large calls by value, but I'm getting this
error for constructors that pass merely an extra int. I recently downloaded
Update 4 and it didnt help. Any ideas?
Thanks
 
 

Re:Stack Overflow on Form Creation

sctrojan79 wrote:
Quote
... but I'm getting this
error for constructors that pass merely an extra int. .
That is the whole point. Do not use a constructer that has only
one extra int. Or reverse the sequence of the parameters.
The constructor with an int extra does already exist in the TForm class,
hence the recursion.
Hans.
 

Re:Stack Overflow on Form Creation

"sctrojan79" < XXXX@XXXXX.COM >wrote in message
Quote
I'm having trouble with adding additional constructors to forms.
In most cases, the very existence of a non-default constructor
will cause a 'Stack Overflow' error on form creation
That is not true. It only happens under a very specific situation only.
You cannot override the TForm(TComponent*, int) constructor. Doing so will
introduce an endless recursion loop, because VCL constructors are virtual
and TForm(TComponent*) calls TForm(TComponent*, int) internally. If your
override of TForm(TComponent*, int) calls TForm(TComponent*) (which is often
the case), the recursion occurs.
Quote
I'm getting this error for constructors that pass merely an extra int.
Exactly, because TForm already has such a constuctor defined for internal
use and should not be overriden in your own code. That is the situation
that you must avoid. If you must pass an extra 'int' parameter, then you
must make it be the first parameter, not the second parameter, so that the
function signature of your constructor is different than the signature of
the native constructor, thus is won't be overriden and thus won't cause a
recursive error.
Gambit
 

{smallsort}

Re:Stack Overflow on Form Creation

"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
The constructor with an int extra does already
exist in the TForm class, hence the recursion.
The mere presense of the constructor is not the reason the recursion occurs.
It occurs because the constructor that does not take an int parameter calls
the constructor that does, and because VCL constructors are virtual, the
constructor that does not take an int parameter will end up calling your
overriden constructor, which will call the constructor without an int
parameter, which will call your constructo, and so on endlessly until the
stack overflows.
Gambit