Solved

Calculated fields

Posted on 1998-05-06
4
468 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

778 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