Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 15 total
Thread Cancelling Master Dataset Posts Child
Mon, Jun 30 2008 2:15 AMPermanent Link

"Adam H."
Hi,

I've got a problem in one of my applications but can't for the life of me
find out what's going on.

The problem is as follows:

I have two DBISamTables in a master/detail relationship.

I put the master table in Edit mode, and then put the Detail table in Edit
mode.

If the user clicks on a dbnavigator for the mater table, and clicks the
cancel button - the detail table wants to save the change! (do a post)

I can't figure out why this is happening. It's my understanding that if the
master table is cancelled, so should the detail table.

When I vew the callstack on the 'beforepost' event of the detail table I get
the following:

PackingInstDM.TDMPackingInst.PackInstDetTBeforePost($5F5D950)
:00519e93 TDataSet.DoBeforePost + $1B   ******** How did we get here????
:00519b53 TDataSet.CheckBrowseMode + $47
:0051382e TDataSource.NotifyDataLinks + $16
dbisamtb.TDBISAMTable.DataEvent(deCheckBrowseMode,0)
:005194ea TDataSet.Cancel + $32
dbisamtb.TDBISAMDataSet.Cancel   ********* Looks like it's going to cancel
the master table...
:005b1fbe TDBNavigator.BtnClick + $E2   **********Clicks on the CANCEL
button
:005b1e18 TDBNavigator.ClickHandler + $14
:005b255d TNavButton.MouseUp + $1D
:004d59c9 TControl.DoMouseUp + $31
:004d4d4b TControl.Perform + $27
:004d8baa TWinControl.IsControlMouseMsg + $A6
:004d87df TWinControl.MainWndProc + $2F
:0043411e StdWndProc + $16
:75eef8d2 USER32.GetMessageW + 0x93
:75eef794 ; C:\Windows\system32\USER32.dll
:75ef0008 ; C:\Windows\system32\USER32.dll
:75ee5a2c USER32.DispatchMessageA + 0xf
:004f4acd TApplication.ProcessMessage + $101


I have checked the BeforePost event of the detail table and it is only
linked to the onbeforepost event of the dataset. (And not on the
beforecancel which I thought it might have been).

I'm not sure how else to track what is happening here. Does anyone have any
ideas?

Thanks & Regards

Adam.
Mon, Jun 30 2008 2:34 AMPermanent Link

"Adam H."
More information...

I've found if I make a test application I have the same problem, but it
doesn't always do the post - sometimes it cancells.

To make it cancel:

masterds.edit;
detailds.edit;
masterds.cancel;  //Detail dataset will cancel here too.


BUT

masterds.edit;
detailds.edit;
detailds.findfield('somefield').value := something;
masterds.cancel;  //Detail dataset will SAVE the changes.

I'm beginning to wonder if this has been designed this way.

Cheers

Adam.
Mon, Jun 30 2008 4:03 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Adam


My take on it is that the two tables are linked for display purposes, not for editing purposes - after all a master-detail relationship can have many detail rows for one master row and putting the master table into edit does not put the detail table into edit.

What's happening (my guess) is that cancelling the master table essentially calls for a refresh of the link (just in case something was changed I suppose). When the detail table is refreshed Delphi/DBISAM know if the table has changed or not. If not it cancels, but if it has it posts.

In my app I have to do a field := field to get it to post so my after post event runs.

What you need to do is use the BeforeCancel event of the master table to cancel any editing of the detail table.

This is the easy scenario. If you have something like an invoice & invoice lines you have to track all the changes to the lines and undo them in the event of a cancel. I'd use an in-memory table and some sql to update the detail table in either the before or after post events.

Roy Lambert [Team Elevate]
Mon, Jun 30 2008 11:44 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< I'm beginning to wonder if this has been designed this way. >>

Yep, and Roy's explanation is 100% correct.  Just do a Cancel on the detail
in the master's BeforeCancel, and you'll be all set.

--
Tim Young
Elevate Software
www.elevatesoft.com

Mon, Jun 30 2008 7:02 PMPermanent Link

"Adam H."
Good Morning Roy,

Thanks for your reply...

> What you need to do is use the BeforeCancel event of the master table to
> cancel any editing of the detail table.

I actually tried this, and to my surprise the detail table still did it's
post before this event was triggered! Frown

Cheers

Adam.
Mon, Jun 30 2008 7:50 PMPermanent Link

"Adam H."
Hi Gentlemen,

I've come up with a temporary solution at present. Unfortuantly it doesn't
work with DBNavigators or the like, but if you have a custom cancel button,
the following will work:

procedure Button1.click;
begin
 cancellinkeddatasets(mytable);
 mytable.cancel;
end;

procedure cancellinkeddatasets(Dataset : TDataset);
var
 list : TList;
 i : integer;
 s : string;
begin
 list := Tlist.create;
 dataset.GetDetailDataSets(list);
 for i := 0 to list.Count - 1 do
  begin
  cancellinkeddatasets(TDataset(list.Items[i]));
  dataset.cancel;
  end;
  list.Free;
  list := nil;
end;

This will get me out of immediate trouble, but I'm still concerned that the
beforecancel event doesn't trigger until after the linked datasets have
already been posted under normal circumstances.

Cheers

Adam.
Mon, Jun 30 2008 8:33 PMPermanent Link

"Robert"

"Adam H." <ahairsub4@pleaseREMOVEme.jvxp.com> wrote in message
news:2CA1E819-40C6-43EF-9E60-6DBF152B55C7@news.elevatesoft.com...
> Good Morning Roy,
>
> Thanks for your reply...
>
>> What you need to do is use the BeforeCancel event of the master table to
>> cancel any editing of the detail table.
>
> I actually tried this, and to my surprise the detail table still did it's
> post before this event was triggered! Frown
>

Then something is causing the detail table to scroll. A change in the key
maybe?

Just take a look at where you are in the detail before post, and that should
shed some light on what's going on.

Robert

Tue, Jul 1 2008 2:08 AMPermanent Link

"Adam H."
Good Afternoon Robert,

Thanks for your reply...

>>> What you need to do is use the BeforeCancel event of the master table to
>>> cancel any editing of the detail table.
>>
>> I actually tried this, and to my surprise the detail table still did it's
>> post before this event was triggered! Frown
>>
>
> Then something is causing the detail table to scroll. A change in the key
> maybe?
>
> Just take a look at where you are in the detail before post, and that
> should shed some light on what's going on.

I've created a brand new project with only two tables, two datasets, (one
table linked to the other), two grids, and two DBNavigator controls and no
coding behind the scene (except for a few showmessages on different events
so I can see which ones fire first), and still have the same problem - so
from what I can tell, this is native to the datasets themselves.

Best regards

Adam.
Tue, Jul 1 2008 2:23 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Adam


I'm with Robert on this one. Something else must be causing the post. Bound controls, events?

Roy Lambert [Team Elevate]
Tue, Jul 1 2008 2:53 AMPermanent Link

"Adam H."
Hi Roy,

> I'm with Robert on this one. Something else must be causing the post.
> Bound controls, events?

Thanks for the confirmation. I've just gone back and think I've found part
of the problem.

The grids I were using in my test sample were TcxGrids. When I drop back to
TDBGrids it behaves as I would expect!

In my application I'm using dev express controls, so I'm assuming that this
is the common link.

So, from what I can tell - the problem must have something to do with the
way Quantumgrids interact with the datasources / datasets.  Strangely
enough, the anomoly occurs even if the grids gridmode property is set to
True.

I'll go chase up Devexpress instead now that I've found the cause.

Thanks for your help guys!

Adam.
Page 1 of 2Next Page »
Jump to Page:  1 2
Image