Re: Calculated Fields Question for the pros


[ Related Articles and Replies ] [ DelphiLand Discussion Forum ]

Posted by webmaster Guido on January 29, 2003 at 17:52:40:

In Reply to: Calculated Fields Question for the pros posted by Peterson on January 28, 2003 at 21:08:51:

: I have two databases (paradox): Currency fields in one and a number fields in the other. I am creating a Calculated field based on currency and percentage.

: What I have so far:

: procedure TForm1.Table1CalcFields(DataSet: TDataSet);
: begin
: Table1AgentGrossComm.Value := (Table1Coy_Gross_Commision.Value * Table2Split_Level.Value);
: End;
: Result is I get all $0.00 in the Calculated field. If I put in "0.65" in place of Table2Split_Level.Value (without the quotes of course) the calculation works perfectly.

: In Table1 the field is defined as : Table1Coy_Gross_Commision: TCurrencyField;
: In Table2 the field is defined as : Table2Split_Level: TFloatField;

: I hope this is clear you, Would you be able to explain what I am doing wrong?

--------------

Some ideas:

1. How is Table2 linked to Table1, how is it positioned? Are you using the correct index for Table2?

2. Are you sure that Table2 is positioned at the correct record? Maybe Table2 is at the EOF (past the last record), because the record was not found that corresponds with the Table1 record?

Suggestion: you could add a calculated field for testing purposes, for example: an alpha-field with the name "Pos", that gives an indication as to where Table2 is positioned. It would show either the contents of an alpha-field of Table2 that is different for each record, some kind of record-number (Paradox db's don't have a real rec number), or it would say "EOF" if Table2 is at the end-of-file.
For this, you could use an existing alpha field of Table2, if there is one that is different for each record. Otherwise, temporarily add an alpha-field (text field) to Table2, named "Posit", and use the database-desktop utility to write something in "Posit" it for each record of Table2: "A" in the first record, "B" in the second, and so on... (or just plain "1", "2", "3"...)

Next, temporarily add a calculated field "Pos" to Table1. In the Table1CalcFields procedure, add some code to show where you are in Table2:

if Table2.EOF then
  Table1Pos.Value := 'Table2 EOF' 
else
  Table1Pos.Value := Table2Posit.Value;
Maybe let us know if it worked? Good luck! 

Related Articles and Replies:


[ DelphiLand Discussion Forum ]