Board index » delphi » to count with databasefields

to count with databasefields

help me please!
how  can  I count with database-fields, like field3=: field1+field2.
Someone can  give me a more realistic example.

Thank you

Dieter

 

Re:to count with databasefields


Hello,
I'm not sure what you are trying to do, but if the content of one field is
supposed to be a summary of the content of two others -  this could be the
syntax:

Table1.Fieldbyname('FIELD3').AsInteger :=
Table1.Fieldbyname('FIELD1').AsInteger +
Table1.Fieldbyname('FIELD2').AsInteger;

--
Regards
Kai Inge

{If it's not broke - don't fix it.}

Quote
U.Rott wrote in message <3783A987.1C71...@ix.urz.uni-heidelberg.de>...
>help me please!
>how  can  I count with database-fields, like field3=: field1+field2.
>Someone can  give me a more realistic example.

>Thank you

>Dieter

Re:to count with databasefields


On Wed, 07 Jul 1999 21:24:55 +0200, "U.Rott" <o...@ix.urz.uni-heidelberg.de>
wrote:

Quote
>how  can  I count with database-fields, like field3=: field1+field2.
>Someone can  give me a more realistic example.

You could use the Fields property of the dataset component to refer to the
target field and source fields by their ordinal position in the table's
structure. Use properties of TField for getting and setting a field's
value, such as the TField.Value property. Put the dataset in edit mode
first by calling its Edit method. After assigning a value to the target
field, finalize the operation by calling the dataset's Post method.

  Table1.Edit;
  Table1.Fields[3].Value := Table1.Fields[1].Value +
    Table1.Fields[2].Value;
  Table1.Post;

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski     "An inventor is a person who makes an ingenious
Felton, CA         arrangement of wheels, levers and springs, and believes
                   it civilization."          -- Ernest Dimnet (1866-1954)

Re:to count with databasefields


Hello,

I would think that by using the field position property he is programming a
little timing bomb for himself.
If there are more fields containing numbers - and the fields position are
changed by fx a DBGrid, then suddenly the calculation quietly gives you a
wrong answer. :)

The name property is safer programming?

--
Regards
Kai Inge

{If it's not broke - don't fix it.}

Quote
Steve Koterski wrote in message <3786c236.10575...@news.gte.net>...
>On Wed, 07 Jul 1999 21:24:55 +0200, "U.Rott" <o...@ix.urz.uni-heidelberg.de>
>wrote:

>>how  can  I count with database-fields, like field3=: field1+field2.
>>Someone can  give me a more realistic example.

>You could use the Fields property of the dataset component to refer to the
>target field and source fields by their ordinal position in the table's
>structure. Use properties of TField for getting and setting a field's
>value, such as the TField.Value property. Put the dataset in edit mode
>first by calling its Edit method. After assigning a value to the target
>field, finalize the operation by calling the dataset's Post method.

>  Table1.Edit;
>  Table1.Fields[3].Value := Table1.Fields[1].Value +
>    Table1.Fields[2].Value;
>  Table1.Post;

>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>Steve Koterski     "An inventor is a person who makes an ingenious
>Felton, CA         arrangement of wheels, levers and springs, and believes
>                   it civilization."          -- Ernest Dimnet (1866-1954)

Re:to count with databasefields


On Thu, 8 Jul 1999 19:09:20 +0200, "Kai Inge Buseth" <kibus...@online.no>
wrote:

Quote
>I would think that by using the field position property he is programming a
>little timing bomb for himself.
>If there are more fields containing numbers - and the fields position are
>changed by fx a DBGrid, then suddenly the calculation quietly gives you a
>wrong answer. :)

>The name property is safer programming?

Well, it sure was not clear to me that this could even enter into the
equation. But yes, if columns might be moving about referencing them by
their names rather than their oridinal positions would be safer and more
logical.

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski     "An inventor is a person who makes an ingenious
Felton, CA         arrangement of wheels, levers and springs, and believes
                   it civilization."          -- Ernest Dimnet (1866-1954)

Other Threads