Board index » cppbuilder » Stack overflow

Stack overflow


2003-07-26 08:11:30 PM
cppbuilder98
Hi,
I want to pass an ID as a parameter to the constructor of a
form. The id is an int, but when I construct the form in the
application, I get a stack overflow. As soon as I change the
parameter type to bool or double or AnsiString or whatever, it
doesn't give me this error. I only want to pass one int
parameter to the constructor, but I currently use lots of int
variables to work with the ID (having names such as cur_id,
link_id, idtemp etc). Can that be the problem? If not, what
could the problem be?
Thanks for your help!
 
 

Re:Stack overflow

please show us your constructor code that is failing..
Andrew wrote:
Quote
Hi,

I want to pass an ID as a parameter to the constructor of a
form. The id is an int, but when I construct the form in the
application, I get a stack overflow. As soon as I change the
parameter type to bool or double or AnsiString or whatever, it
doesn't give me this error. I only want to pass one int
parameter to the constructor, but I currently use lots of int
variables to work with the ID (having names such as cur_id,
link_id, idtemp etc). Can that be the problem? If not, what
could the problem be?

Thanks for your help!
 

Re:Stack overflow

Andrew wrote:
Quote
I want to pass an ID as a parameter to the constructor of a
form. The id is an int, but when I construct the form in the
application, I get a stack overflow.
Have a look at:
Date: Thu, 24 Jul 2003 19:07:31 +0200
From: Jonathan Neve <jonathan@!nospam!microtec.fr>
Newsgroups: borland.public.cppbuilder.language.cpp
Subject: Stack overflow
Hans.
 

{smallsort}

Re:Stack overflow

"Andrew" < XXXX@XXXXX.COM >wrote in message
Quote
I want to pass an ID as a parameter to the constructor
of a form. The id is an int, but when I construct the form
in the application, I get a stack overflow.
TCustomForm already has a constructor that takes an 'int' as a parameter,
which is called internally during the form's creation. By overriding it
with your own constructor that also takes an 'int', you are introducing an
endless recursion loop, thus the stack overflow.
Quote
As soon as I change the parameter type to bool or
double or AnsiString or whatever, it doesn't give me this
error.
Correct.
To do what you ask, the simpliest solution is to simply reverse the order of
your constructor's parameters, so that the 'int' is in front of the list
rather than in the back of it, ie:
__fastcall TMyForm::TMyForm(int ID, TComponent *Owner)
: TForm(Owner)
{
// use ID as needed
}
Gambit
 

Re:Stack overflow

In the OnClick event for the TMenuItem RestrictMailings1 I have the
following. The OnClick event of TCheckBox1 is also directed to this
procedure. When it's called, the checks flicker for a few seconds and then I
get a stack overflow error. How may I circumvent this?
procedure TSpamPage.RestrictMailings1Click(Sender: TObject);
begin
if RestrictMailings1.Checked and CheckBox1.Checked then
begin
RestrictMailings1.Checked := False;
CheckBox1.Checked := False;
end
else
begin
RestrictMailings1.Checked := True;
CheckBox1.Checked := True;
end;
end;
--
Yours
Rhys
Join the anti-spam project:
groups.yahoo.com/group/Anti-Spam-Development/
or view my website:
www.sageworld.freeserve.co.uk
"Software is always designed to be operated by the average 8 year old.
Sadly,
most users never aspire to that level of intelligence."
 

Re:Stack overflow

"Rhys Sage" < XXXX@XXXXX.COM >wrote in message
Quote
In the OnClick event for the TMenuItem RestrictMailings1 I have the
following. The OnClick event of TCheckBox1 is also directed to this
procedure.
A stack overflow is usually the result of a recursive operation gone wild.
In your case, changing the checked status of the checkbox generates an
onclick event.
Robert
 

Re:Stack overflow

-
In article < XXXX@XXXXX.COM >, "Rhys Sage" < XXXX@XXXXX.COM >
wrote:
Quote
In the OnClick event for the TMenuItem RestrictMailings1 I have the
following. The OnClick event of TCheckBox1 is also directed to this
procedure.
So its like writing:
procedure OnClick;
begin
OnClick;
OnClick;
end;
Quote
When it's called, the checks flicker for a few seconds and then I
get a stack overflow error. How may I circumvent this?
var busy:boolean;
Quote
procedure TSpamPage.RestrictMailings1Click(Sender: TObject);
begin
if not busy then begin
busy:=True;
Quote
if RestrictMailings1.Checked and CheckBox1.Checked then
begin
RestrictMailings1.Checked := False;
CheckBox1.Checked := False;
end
else
begin
RestrictMailings1.Checked := True;
CheckBox1.Checked := True;
end;
busy:=false;
end;
Quote
end;
 

Re:Stack overflow

Hmm. Very strange.
I now have the following code for my program. Busy is global. The problem is
that when change the onchecked property from the TMainMenu item
(RestrictMailings1), I can uncheck and check both RestrictMailings1 and
CheckBox1. From CheckBox1 I can only check both. I cannot uncheck either.
This is most puzzling. I enclose also the code generating the appropriate
visual bits.
procedure TSpamPage.RestrictMailings1Click(Sender: TObject);
begin
if Busy then exit;
Busy := True;
if RestrictMailings1.Checked and CheckBox1.Checked then
begin
RestrictMailings1.Checked := False;
CheckBox1.Checked := False;
end
else
begin
RestrictMailings1.Checked := True;
CheckBox1.Checked := True;
end;
Busy := False;
end;
procedure TSpamPage.FormCreate(Sender: TObject);
begin
Busy := False;
end;
object CheckBox1: TCheckBox
Tag = 1
Left = 8
Top = 336
Width = 337
Height = 17
Caption = 'Restrict first mailings to one per domain'
Checked = True
State = cbChecked
TabOrder = 1
OnClick = RestrictMailings1Click
end
object RestrictMailings1: TMenuItem
Caption = '&Restrict Mailings'
Checked = True
GroupIndex = 7
OnClick = RestrictMailings1Click
end
--
Yours
Rhys
Join the anti-spam project:
groups.yahoo.com/group/Anti-Spam-Development/
or view my website:
www.sageworld.freeserve.co.uk
"Software is always designed to be operated by the average 8 year old.
Sadly,
most users never aspire to that level of intelligence."
 

Re:Stack overflow

Rhys,
That seems to indicate that when you try to uncheck from CheckBox1 the
Checked property of 3each checkbox is not being shown as "Checked". I
don't recall off hand, but is the checked property for a checkbox
ALREADY changed by the time you get to the event handler and NOT ALREADY
changed when called from a menu item?
The way we did this in another app was to reference the Sender param and
see if (Sender = CheckBox1) then.... For our case that worked well.
I remember thinking I was getting loopy the first time I had to figure
out the process. :)
Allen.
 

Re:Stack overflow

Hi Rhys,
here is how I avoid this sort of problem...
"Rhys Sage" < XXXX@XXXXX.COM >wrote in message
Quote
Hmm. Very strange.

I now have the following code for my program. Busy is global. The problem
is
that when change the onchecked property from the TMainMenu item
(RestrictMailings1), I can uncheck and check both RestrictMailings1 and
CheckBox1. From CheckBox1 I can only check both. I cannot uncheck either.
This is most puzzling. I enclose also the code generating the appropriate
visual bits.

procedure TSpamPage.RestrictMailings1Click(Sender: TObject);
var
SaveEvent: TNotifyEvent;
Quote
begin
SaveEvent := RestrictMailings1.OnClick;
RestrictMailings1.OnClick := nil;
try
Quote
if RestrictMailings1.Checked and CheckBox1.Checked then
begin
RestrictMailings1.Checked := False;
CheckBox1.Checked := False;
end
else
begin
RestrictMailings1.Checked := True;
CheckBox1.Checked := True;
end;
finally
RestrictMailings1.OnClick := SaveEvent;
end;
Quote
end;

<snip>
Dan Rhea
Software Engineer III
ProQuest Information and Learning
561-994-0079 x757
www.sirs.com www.bigchalk.com
 

Re:Stack overflow

Aha.
It seems that TCheckBoxes all onclick after the box has been checked.
TMenuItems on the other hand, onclick BEFORE they have been checked.
The following works perfectly.
procedure TSpamPage.RestrictMailings1Click(Sender: TObject);
begin
if Busy then exit;
Busy := True;
if (Sender = CheckBox1) then
begin
if CheckBox1.Checked then RestrictMailings1.Checked := True
else
begin
RestrictMailings1.Checked := False;
end;
end;
if (Sender = RestrictMailings1) then
begin
if not RestrictMailings1.Checked then
begin
CheckBox1.Checked := True;
RestrictMailings1.Checked := True;
end
else
begin
RestrictMailings1.Checked := False;
CheckBox1.Checked := False;
end;
end;
Busy := False;
end;
--
Yours
Rhys
Join the anti-spam project:
groups.yahoo.com/group/Anti-Spam-Development/
or view my website:
www.sageworld.freeserve.co.uk
"Software is always designed to be operated by the average 8 year old.
Sadly,
most users never aspire to that level of intelligence."
 

Re:Stack overflow

"Sergio" < XXXX@XXXXX.COM >wrote
Quote
When I execute a select sentence, I got this error:
STACK OVERFLOW.
Sergio,
Do you have event handlers assigned that are calling
each other in a circular or recursive fashion?
Regards, JohnH
 

Re:Stack overflow

Hello everybody,
my table products.db <---- 32 MB
when i execute a select sentence, i got this error:
STACK OVERFLOW.
and I need take the records to put it in another database.
Thanks
sorry my english.
Sergio.
 

Re:Stack overflow

Hi John,
is not recursive, is not circular.
its only an "select * from products" . Add the "Where" clause, is the same
problem.
I use paradox 7 tables, and i execute the query on DatabaseExplorer of
Delphi 5.
I really need the migration of this records.
Sergio
"John Herbster (TeamB)" <herb-sci1_AT_sbcglobal.net>escribi?en el mensaje
Quote

"Sergio" < XXXX@XXXXX.COM >wrote
>When I execute a select sentence, I got this error:
>STACK OVERFLOW.

Sergio,
Do you have event handlers assigned that are calling
each other in a circular or recursive fashion?
Regards, JohnH
 

Re:Stack overflow

Hi all, I just tried to write my first graphical component, so please don't
tease.... ;) I wrote my own progressbar as I need it to include text other
than just the percent. It seems to work ok until I try to set the text of
the component in the Paint method. I get a stack overflow in runtime but not
in designtime.... any help would be greatly appreciated as I really do not
know what I am doing wrong.... oops, I do not know what I am doing at all.
... here is my code so far...
class PACKAGE TCDSProgressBar : public TGraphicControl
{
private:
long FMin;
long FMax;
long FProgress;
AnsiString FPText;
TColor FBackgroundColor;
TColor FForegroundColor;
bool FShowText;
void __fastcall SetProgress(long value);
void __fastcall SetPText(AnsiString value);
void __fastcall SetShowText(bool value);
void __fastcall SetBackgroundColor(TColor);
void __fastcall SetForegroundColor(TColor);
void __fastcall SetTextColor(TColor);
protected:
virtual void __fastcall Paint(void);
public:
__fastcall TCDSProgressBar(TComponent* Owner);
__published:
__property long Max = { read=FMax, write=FMax };
__property long Progress = { read=FProgress, write=SetProgress };
__property AnsiString PText = { read=FPText, write=SetPText };
__property TColor BackgroundColor = { read=FBackgroundColor,
write=SetBackgroundColor };
__property TColor ForegroundColor = { read=FForegroundColor,
write=SetForegroundColor };
__property bool ShowText = { read=FShowText, write=SetShowText };
};
//--------------------------------------------------------------------------
-
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TCDSProgressBar *)
{
new TCDSProgressBar(NULL);
}
//--------------------------------------------------------------------------
-
__fastcall TCDSProgressBar::TCDSProgressBar(TComponent* Owner)
: TGraphicControl(Owner)
{
FMin = 0;
FMax = 100;
FProgress = 0;
}
//--------------------------------------------------------------------------
-
namespace Cdsprogressbar
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TCDSProgressBar)};
RegisterComponents("CompuData", classes, 0);
}
}
//--------------------------------------------------------------------------
-
void __fastcall TCDSProgressBar::SetProgress(long value)
{
//TODO: Add your source code here
FProgress = value;
Paint();
}
//--------------------------------------------------------------------------
-
void __fastcall TCDSProgressBar::Paint(void)
{ // This is the guts of it right here
// Fetch the current progress in pixels
long ForegroundWidth = Width>= FMax?(Width / FMax) * FProgress:1;
long BackgroundWidth = Width;
// Now calculate both rectangles
TRect ProgressRect(0,0,ForegroundWidth,Height);
TRect
BackgroundRect(ForegroundWidth,0,BackgroundWidth+ForegroundWidth,Height);
// Ok, lets draw them now
Canvas->Brush->Color = FForegroundColor;
Canvas->FillRect(ProgressRect);
Canvas->Brush->Color = FBackgroundColor;
Canvas->FillRect(BackgroundRect);
// Moving right along to the Text property
AnsiString T = PText;
// if we are to show the percent as well, then lets check this out
if(FShowText && T.Length()) {
long OurProgress;
if(FProgress>= 100) OurProgress = (FProgress / 100);
else if(FProgress == 0) OurProgress = 0;
else OurProgress = 1;
T = T + AnsiString(" ") + IntToStr(OurProgress);
}
Canvas->TextRect(TRect(Left + 2,Top + 2,Left + (Width-2),Top +
(Height-2)),2,2,T);
}
//--------------------------------------------------------------------------
-
void __fastcall TCDSProgressBar::SetPText(AnsiString value)
{
PText = value;
Paint();
}
//--------------------------------------------------------------------------
-
void __fastcall TCDSProgressBar::SetForegroundColor(TColor value)
{
FForegroundColor = value;
Paint();
}
//--------------------------------------------------------------------------
-
void __fastcall TCDSProgressBar::SetBackgroundColor(TColor value)
{
FBackgroundColor = value;
Paint();
}
//--------------------------------------------------------------------------
-
void __fastcall TCDSProgressBar::SetShowText(bool value)
{
FShowText = value;
Paint();
}
//--------------------------------------------------------------------------
-