Re: Calculated Fields Question for the pros


[ Related Articles and Replies ] [ DelphiLand Discussion Forum ]

Posted by webmaster Guido on February 15, 19103 at 15:11:39:

In Reply to: Re: Calculated Fields Question for the pros posted by Peterson on February 14, 19103 at 19:57:55:

: I reference to my previous post;
: Maybe I can explain this a little better:

: In Table2 The Database consists of different agents with different Percentages.
: Eg:

: Agent1 = 65%
: Agent2 = 90%
: Agent3 = 72%
: Etc....

: Based on the record in Table1 (which Agent is conducting the deal) I want to mathematicaly determine thier commission and display it.
: Does this make more sense?

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

You didn't answer to my previous questions ;-) so it's impossible for me to figure out what is going wrong... Let me repeat, with some more explanations:

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

Table2 must follow the "movements" of Table1. There are two ways to accomplish this:

A. Automatically: link the TTable components in the Object Inspector, using the properties MasterFields and MasterSource of Table2.
B. In code: position Table2 to the desired record in the Table1CalcFields procedure.

Let's look at the code snippet that you posted:

procedure TForm1.Table1CalcFields(DataSet: TDataSet);
begin
Table1AgentGrossComm.Value := (Table1Coy_Gross_Commision.Value * Table2Split_Level.Value);
End;

As I saw no positioning of Table2 in your code, I assumed that you use automatic linking of the tables, as in method A above. But maybe you're not using any of the 2 methods?
If you want to use method B, you have to complete Table1CalcFields with code that positions Table2 to the desired record, for example:

procedure TForm1.Table1CalcFields(DataSet: TDataSet);
begin
Table2.FindKey([Table1Agent.Value]);
Table1AgentGrossComm.Value := (Table1Coy_Gross_Commision.Value * Table2Split_Level.Value);
End;

For any linking method, both tables must have an identical field (field "Agent" in the example, of type alpha-numeric) of the same size. Of course, all the values of Table1Agent must exist in Table2Agent.

Further on, if you use automatic linking, or linking in code with a "FindKey" command, or GotoKey, or whatever code that requires an index, Table2 must be indexed on field "Agent". Of course, you could also write some positioning mechanism that doesn't require an index, but that's not recommended (would be more difficult, and works slower).

Let us know if this solved your problem. Good luck!


Related Articles and Replies:


[ DelphiLand Discussion Forum ]