procedure TFmCtrlGrid.FormShow(Sender: TObject);
begin
  DM1.CalculateTotals(Sender, nil);
end;
 
是Demos\DB\CtrlGrid例子里的

解决方案 »

  1.   

    应该是计算合计的.
    全文查询下CalculateTotals
      

  2.   

    procedure TDM1.CalculateTotals(Sender: TObject; Field: TField);
    var
      flTotalCost,            { Holds total share cost }
      flTotalShares,          { Holds total share count }
      flTotalValue,           { Holds total share value }
      flDifference: Real;     { Holds difference between cost and value }
      strFormatSpec: string;  { The Display Format specification }
    begin  { Update the count of stock transactions }
      FmCtrlGrid.lPurchase.Caption := IntToStr( tblHoldings.RecordCount );  { See whether or not its necessary to total the holdings and
        (if so) do so and update the result displays; otherwise,
        clear the result displays. }
      if tblHoldings.recordCount = 0 then
      begin
        { Clear the result displays }
        FmCtrlGrid.lTotalCost.Caption   := '';
        FmCtrlGrid.lTotalShares.Caption := '';
        FmCtrlGrid.lDifference.Caption  := '';
      end
      else
      begin
        { let the user know something's going on }
        Screen.Cursor := crHourglass;    { Initialize the holder variables }
        flTotalCost := 0.0;
        flTotalShares := 0.0;    { Calculate the total cost of these holdings. }
        tblHoldings.disableControls;  { hide this process from the user }
        tblHoldings.first;
        while not tblHoldings.eof do
        begin
          flTotalCost := flTotalCost + tblHoldingsPUR_COST.AsFloat;
          flTotalShares := flTotalShares + tblHoldingsSHARES.AsFloat;
          tblHoldings.next;
        end;
        tblHoldings.first;
        tblHoldings.enableControls;  { restore the display of holdings }    { Calculate the current value of the shares (by multiplying
          the current holdings by the current share price) and the
          difference between the cost and the value. }    flTotalValue := flTotalShares * tblMasterCUR_PRICE.AsFloat;
        flDifference := flTotalValue - flTotalCost;    { Use the same format specification as that being used to
          display the Current Price field value so it can be used
          to display the results }    strFormatSpec := tblMasterCUR_PRICE.DisplayFormat;    { Update the result displays }    FmCtrlGrid.lTotalCost.Caption :=
           FormatFloat( strFormatSpec, flTotalCost );
        FmCtrlGrid.lTotalShares.Caption :=
           FormatFloat( strFormatSpec, flTotalValue );
        FmCtrlGrid.lDifference.Caption :=
           FormatFloat( strFormatSpec, flDifference );    { Update the Font Color of the Diference to
          indicate the quality of the investment }
        if flDifference > 0 then
          FmCtrlGrid.lDifference.Font.Color := clGreen
        else
          FmCtrlGrid.lDifference.Font.Color := clRed;
        FmCtrlGrid.lDifference.update;    { let the user know that we're finished }
        Screen.Cursor := crDefault;
      end;
    end;什么功能自己看下
      

  3.   

    谢谢,看懂了!
    妈的,这个例子的名字起的n怪,
    窗体的name是ctrlGrid,
    我看来看去,窗体上只有一个ctrlGrid,害的我找了半夜,
    日~!
      

  4.   

    不过,这个例子还是有不懂的地方,窗体里的ctrlGrid,里的eidt是如何显示值的,好像代码里面没有的?