Subject Re: [IBO] Master/Detail - problems
Author Woody (TMW)
OK, it has something to do with calculated fields. I have a calculated field
called Total in the detail. This is used to total the item based on quantity
and price. Also, a total of all items is displayed. To do this, I call a
procedure which loops through the buffered recordset to total the order each
time OnCalculateField is called. When I remove this, the detail records
display correctly. Since this code was there before the update, I can only
assume that something has changed to break it. Perhaps the control grid uses
the buffer somehow and I am screwing it up by iterating through it.

Here is the code for the calculation:

procedure TfrmWorkOrders.CalculateItemTotals;
var
tmpCol: TIB_Column;
Total: double;

begin
tmpCol := WOItems.BufferFieldByName('Total');
WOItems.BeginBusy(false);
Total := 0;
try
WOItems.BufferFirst;
while not WOItems.BufferEOF do begin
Total := Total + (WOItems.BufferFieldByName('Qty').AsInteger *
WOItems.BufferFieldByName('Price').AsFloat);
WOItems.BufferNext;
end;
finally
WOItems.EndBusy;
edItemsTotal.Text := FormatFloat('$##,###,##0.00', Total);
end;
end;

Here is the OnCalculateField code:

procedure TfrmWorkOrders.WOItemsCalculateField(Sender: TIB_Statement;
ARow: TIB_Row; AField: TIB_Column);
begin
if (AField.FieldName = 'TOTAL') then
with ARow do
ByName('Total').AsString := FormatFloat('#,###,##0.00',
(ByName('Qty').AsInteger * ByName('Price').AsFloat));
CalculateItemTotals;
end;

Removing the call to CalculateItemTotals in the OnCalculateField event
clears up the detail display problem.

Any ideas and/or solutions to this?

Woody (TMW)

----- Original Message -----
From: "Jason Wharton" <jwharton@...>
To: <IBObjects@yahoogroups.com>
Sent: Tuesday, November 30, 2004 2:00 PM
Subject: RE: [IBO] Master/Detail - problems


>
> I'm guessing the problem has to do with the TIB_CtrlGrid.
> That control still has some rough edges to file off.
>
> Jason
>
> > -----Original Message-----
> > From: Woody (TMW) [mailto:woody-tmw@...]
> > Sent: Tuesday, November 30, 2004 1:03 PM
> > To: IBO Group
> > Subject: [IBO] Master/Detail - problems
> >
> >
> >
> > Been going around in circles now so thought I'd ask for help. I had a
> > working master detail relation but it stopped working after
> > upgrading to
> > version 4.3a of IBObjects. I don't think it was the update
> > since all others
> > still work fine. Don't know what could have happened here.
> >
> > For simplicity, let's assume my two tables are reduced to
> > their respective
> > key fields:
> >
> > Master table A : ID
> > Detail table B: ID and ItemNum
> >
> > On a control grid (TIB_CtrlGrid), when there is only one
> > detail record, it
> > displays correctly. Now comes the fun part.
> >
> > Add item 2 and the grid now shows two item 2's.
> >
> > Add item 3 and the grid shows one item 2 and two item 3's
> >
> > Add item 4 and the grid shows one item 2, one item 3 and two item 4's.
> >
> > Delete item 4 and the grid shows one item 2 and two item 3's.
> >
> > IOW, process repeats the forward version in reverse.
> >
> > I have checked and rechecked the SQL, KeyLinks, MasterLinks,
> > etc. I still
> > can't figure this one out. I want to delete the detail query
> > and start with
> > a fresh one but I don't want to just give up on this. It may
> > help someone
> > else if I find out the problem.
> >
> > Woody (TMW)
>
>
>
>
>
___________________________________________________________________________
> IB Objects - direct, complete, custom connectivity to Firebird or
InterBase
> without the need for BDE, ODBC or any other layer.
>
___________________________________________________________________________
> http://www.ibobjects.com - your IBO community resource for Tech Info
papers,
> keyword-searchable FAQ, community code contributions and more !
> Yahoo! Groups Links
>
>
>
>
>
>
>