Solved

Calculated fields

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Mdi application Child forms get behind control 7 274
Delphi 2 69
Delphi Seattle StructureView color 1 14
Delphi android app hide keyboard 3 17
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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