Solved

BCB5 Stack overflow problem

Posted on 2007-03-19
2
298 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ Language error 28 316
White board coding practice 3 99
JQuery serialize and unserialize 8 271
How to read a c++ line with strings and variable numbers of elements 6 63
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

751 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