Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

BCB5 Stack overflow problem

Posted on 2007-03-19
2
Medium Priority
?
301 Views
Last Modified: 2013-11-17
I am trying to pass a parameter via the constructor of a TForm but I get a Stack overflow error ?

I have used this method before but not with an integer as a parameter and have had no problems.

Any ideas wy I get the error ? The error is easily demonstrated by the following trivial code:

//header file unit1.h
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:      // IDE-managed Components
    TButton *Button1;
    void __fastcall Button1Click(TObject *Sender);
private:      // User declarations
public:            // User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
// end of unit1.h

// unit1.cpp file
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TForm2 *f;

    f = new TForm2(NULL,2);
    delete f;
}
//---------------------------------------------------------------------------
// end of unit1.cpp file

//unit2.h file
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published:      // IDE-managed Components
private:      // User declarations
public:            // User declarations
    __fastcall TForm2(TComponent* Owner,int n=0);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif
//end of unit2.h file

//unit2.cpp file
#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner,int n)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
// end of unit2.cpp file



0
Comment
Question by:alcindor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
rmmci earned 1500 total points
ID: 18756172
when TForm 2 is created it calls
#pragma option push -w-inl
/* TCustomForm.Create */ inline __fastcall virtual TForm(Classes::TComponent* AOwner) : TCustomForm(AOwner) { }
from Forms.hpp and your getting the Int overflow by adding the int in the creation of
__fastcall TForm2::TForm2(TComponent* Owner,int n)
    : TForm(Owner)
causeing the stack over flow.
A better solution would be to pass via class in the public portion of the class.
0
 
LVL 2

Author Comment

by:alcindor
ID: 18778175
Hello rmmci,
My solution was to pass an int * as the argument which doesn't give the stack overflow and works just fine. I have used this method several times before but always passing a pointer as the argument (usually a pointer to a structure).
The points are yours, I am curious as to why it is ok to use a pointer argument but not an int ?

Thanks for your input,

Roger
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question