Solved

Calculated fields

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get a Metafile from Clipboard and convert it into a PNG to save to file or stream. 2 99
Reconfigure Delphi Install? 2 46
Multiple image collision 13 69
update joined tables 2 31
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

13 Experts available now in Live!

Get 1:1 Help Now