Solved

Calculated fields

Posted on 1998-05-06
4
465 Views
Last Modified: 2010-04-06
I need to know how to create a calculated field that uses a second calculated field that
is contained in a dbgrid.  What I'm looking for basically is for a sum of a grid column
which is itself a calculated field.
0
Comment
Question by:AllenD
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
ID: 1342529
Hi AllenD,

What's the problem? Or am I missing something?

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  DBTables, DB, Grids, DBGrids;

type
  TForm1 = class(TForm)
    Table1: TTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Table1SpeciesNo: TFloatField;
    Table1Category: TStringField;
    Table1Common_Name: TStringField;
    Table1SpeciesName: TStringField;
    Table1Lengthcm: TFloatField;
    Table1Length_In: TFloatField;
    Table1Notes: TMemoField;
    Table1Graphic: TGraphicField;
    Table1Calculate1: TFloatField;
    Table1Calculate2: TFloatField;
    procedure Table1CalcFields(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Table1CalcFields(DataSet: TDataSet);
begin
 with Table1 do begin
  FieldByName('Calculate1').AsVariant := 25;
  FieldByName('Calculate2').AsVariant := FieldByName('Calculate1').AsFloat * 2;
  end;
end;

end.

Regards, ZiF.
0
 

Author Comment

by:AllenD
ID: 1342530
Hi Zif!

The problem I'm having is the second calculated field that operates on the first one is in a different table.  What I'm trying to do is make a running grand total of a line total.  ( I know it's kind of confusing)....to give you a general idea...here's a layout of what I want.

Quantity | Part Number | Price | Line total
3           | 1000             | 5.00  | 15.00                  <= in a dbgrid  Table1
3           | 2000             | 10.00| 30.00


                                     Parts Total        45.00      <= outside the grid. Table2


I hope this gives you a better idea of what I want.
Thanks

Al.
0
 

Author Comment

by:AllenD
ID: 1342531
Not QUITE what I was Looking for...but it gave me the ideas to be able to fix my code...thanks
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1342532
Seems to me you solved it already ....
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now