Board index » delphi » Master/Detail... stack overflow problem

Master/Detail... stack overflow problem

dear all,

I have DBGrid1 in a form, displaying the recs of Table1 (master
table). In DBGrid2 i display the records of Table2 (detail table). Both
DBGrids are in ReadOnly state. A DBNavigator2 linked onto Table2,
allows me to enter into dsEdit or dsInsert state for the detail
table (Table2). I am doing the editing inside a groupbox which
contains various DBEdit components, because the detail table has too
many fields to display them all in DBGrid2.

After doing a modification in those data aware controls and moving to
another DBEdit, or clicking the Post button (i use another DBNavigator
with only Post and Cancel buttons visible, connected to Table2 as well),
I am getting a <Stack Overflow> error.

What's wrong???

thanks in advance

Fotis Kokkoras

 

Re:Master/Detail... stack overflow problem


Quote
>After doing a modification in those data aware controls and moving to
>another DBEdit, or clicking the Post button (i use another DBNavigator
>with only Post and Cancel buttons visible, connected to Table2 as well),
>I am getting a <Stack Overflow> error.

Stack overflows are usually triggered when a piece of code is executed over and
over again in an infinite recursion.  Put some breakpoints into your code (the
pushbuotton on click looks like a good place to start)

If you step through  your code you should be able to figure out what is going
wrong
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Master/Detail... stack overflow problem


Quote
Brian Bushay TeamB wrote:

> >After doing a modification in those data aware controls and moving to
> >another DBEdit, or clicking the Post button (i use another DBNavigator
> >with only Post and Cancel buttons visible, connected to Table2 as well),
> >I am getting a <Stack Overflow> error.

> Stack overflows are usually triggered when a piece of code is executed over and
> over again in an infinite recursion.  Put some breakpoints into your code (the
> pushbuotton on click looks like a good place to start)

> If you step through  your code you should be able to figure out what is going
> wrong

Brian,

there is no code actually i can step through!! When I am getting into
dsEdit state I move the focus to the 1st DBEdit control and disabling
the DBGrid2.

==========================
procedure TForm5ContactPerson.DBNavigator2Click(Sender: TObject;
  Button: TNavigateBtn);
begin
  if Button in [nbInsert,nbEdit] then
    // check that Insert was successful
    if DataModule2.Table2.State in [dsInsert,dsEdit] then begin
      GroupBox1.Enabled:=False;  //contains the master table DBGrid
      GroupBox2.Enabled:=False;  //contains the detail table DBGrid
      GroupBox3.Enabled:=True;   //contains the DBEdits (detail tbl)
      DBEdit1.SetFocus;
    end;
end;
==========================

When i edit something into that DBEdit and tabbing for the next DBEdit
(or clicking into it) I am getting stack overflow.

The same happens if i am in dsInsert mode. Here, as soon as i type the
first char into the DBEdit i am getting stack overflow immediately.

Is it possible, the fact that I have both a DBGrid and a set of DBEdit
controls connected to the same table, to be the source of the problem??
I tried using a different datasource to connect through it all the
DBEdits onto my detail table, but the same happened.

Is there a restriction on master/detail relationships and detail
table edit/insert? This is what i suspect.

To sum up, if i do the insert/edit using the DBGrid, then everything is
fine. But if do the insert/edit using the DBEdits then I am getting
stack overflow.

this is how i am posting or canceling changes. but it doesn't need for
this code to be executed, since the stack overflow happens even if i
am tabbing from the one DBEdit to the next,aften having type something.

==========================
procedure TForm5ContactPerson.DBNavigator3Click(Sender: TObject;
  Button: TNavigateBtn);
begin
 // on successful post or cancel do
  if Datamodule2.Table2.State=dsBrowse then begin
    GroupBox1.Enabled:=True;
    GroupBox2.Enabled:=True;
    DBGrid2.SetFocus;
    GroupBox3.Enabled:=False;
  end;
end;
==========================

thanks

Fotis

Re:Master/Detail... stack overflow problem


Brian,

when does the detail table desides that the record in edit/insert
belongs to the detail set of records that should be displayed??

I guess it is after the post. this seems to be the case when i am
editing into the DBGrid but not when i am editing into the DBEdits
since the stack overflow happens even after tabbing on to DBEdits.
thank again

Fotis kokkoras

Re:Master/Detail... stack overflow problem


Quote
> Stack overflows are usually triggered when a piece of code is executed over and
> over again in an infinite recursion.  Put some breakpoints into your code (the
> pushbuotton on click looks like a good place to start)

> If you step through  your code you should be able to figure out what is going
> wrong

Brian,
I found what couses the stack overflow but i can not figure out
the reason.

Trying to reach as close to the source of the problem as possible,
I selected a field of the detail table and wrote an onValidate event
handler. When i edited DBEdit1 and tabbed to the next DBEdit control
the handler bellow was executed:

================
procedure TDataModule2.Table2ContPersonSurnameValidate(Sender: TField);
begin  //do some stuff
  if DataModule2.Table1.State= dsBrowse then
    if  DataModule2.Table2.State= dsEdit then
      Application.MessageBox('foo', 'Dialog Title',
mb_applmodal+mb_ok+mb_defbutton1);
end;
================

After clicking on the [OK] button in the messagebox the same handler
was encoutered again and again and again.

So, what causes this endless re-invalidation??

Fotis

Re:Master/Detail... stack overflow problem


Quote
>Is it possible, the fact that I have both a DBGrid and a set of DBEdit
>controls connected to the same table, to be the source of the problem??

No

Quote
>Is there a restriction on master/detail relationships and detail
>table edit/insert? This is what i suspect.

No.

It must have something to do with how you are trying to change focus after an
edit has begun.  put the breakpoint in that code or just start commenting out
the code until your form works.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Master/Detail... stack overflow problem


Quote
>when does the detail table desides that the record in edit/insert
>belongs to the detail set of records that should be displayed??

Sorry but that question makes no sense.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Master/Detail... stack overflow problem


Quote
>procedure TDataModule2.Table2ContPersonSurnameValidate(Sender: TField);
>begin  //do some stuff
>  if DataModule2.Table1.State= dsBrowse then
>    if  DataModule2.Table2.State= dsEdit then
>      Application.MessageBox('foo', 'Dialog Title',
>mb_applmodal+mb_ok+mb_defbutton1);
>end;
>================

>After clicking on the [OK] button in the messagebox the same handler
>was encoutered again and again and again.

>So, what causes this endless re-invalidation??

The change in focus from the dialogbox causes the validation to be re-xecuted
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Master/Detail... stack overflow problem


Quote
Brian Bushay TeamB wrote:

> >when does the detail table desides that the record in edit/insert
> >belongs to the detail set of records that should be displayed??

> Sorry but that question makes no sense.

Funny! I agree with you!!  Some copy-paste side effects......
The problem was a LookUp field in the detail table. The detail of that
lookup field, was in the master table......

I just removed it. I can live without it.

Thanks Brian

Fotis

Re:Master/Detail... stack overflow problem


Quote
>The problem was a LookUp field in the detail table. The detail of that
>lookup field, was in the master table......

>I just removed it. I can live without it.

If you change you mind just use a different ttable for the lookup.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Other Threads