All pastes #36853 Raw Edit

Mine

public text v1 · immutable
#36853 ·published 2006-01-15 12:57 UTC
rendered paste body
//create a memory table to store the totals
tblTotals := TMemoryTable.Create;
tblTotals.FieldDefs.Add('TTL_CLASS',ftInteger);
tblTotals.FieldDefs.Add('TTL_SUM',ftCurrency);
tblTotals.InMemory := True;
tblTotals.CreateTable;

//get the transaction totals per transaction classification
tblTransac.First;
while not(tblTransac.Eof) do
  begin
    if tblTotals.Locate('TTL_CLASS',tblTransac.FieldByName('TRN_CLASS').AsInteger,[]) then
      begin
        tblTotals.Edit;
        tblTotals['TTL_SUM'] := TblTotals['TTL_SUM'] + tblTransac['TRN_VALUE'];
        tblTotals.Post;
      end;
    tblTransac.Next;
  end;

//use the total for transaction class 50 in some calcs
if tblTotals.Locate('TTL_CODE',50,[]) then
  ......
  ......

//use the total for transaction class 60 in some calcs
if tblTotals.Locate('TTL_CODE',60,[]) then
  ......
  ......


//free the table containing the totals
tblTotals.Active := False;
tblTotals.Free;