🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.vcl.components.using.dotnet
6 messages
6 total messages Started by Joaquin P. Wed, 11 Jan 2006 09:25
Calc. fields in TClientDataSet.
#65
Author: Joaquin P.
Date: Wed, 11 Jan 2006 09:25
15 lines
1582 bytes
Hi!

    I'm using a TClientDataSet component in a VCL.NET application, and I've 
defined several data and calculated fields.
    Everything is running ok, but I noticed about a 'rare behaviour' of 
calc. fields (TFloatField only):
    * Results of the calculation, having the decimal part '0' or '5' (i.e. 
'24' or '15,5' -we use comma as decimal separator, but I tried using decimal 
point with the same result-), are saved ALWAYS as '0' in the calc. field.
    * Results having any other decimal ('15,1', '15,23', '32,70', '32.70', 
...) are saved CORRECTLY.

    Please, can anybody help me?

    Thanks. 
Re: Calc. fields in TClientDataSet.
#67
Author: Nick Hodges [TeamB]
Date: Wed, 11 Jan 2006 22:00
19 lines
1622 bytes
Joaquin P. wrote:

>  * Results of the calculation, having the decimal part '0' or '5'
> (i.e. '24' or '15,5' -we use comma as decimal separator, but I tried
> using decimal point with the same result-), are saved ALWAYS as '0'
> in the calc. field.    * Results having any other decimal ('15,1',
> '15,23', '32,70', '32.70', ...) are saved CORRECTLY.

Calculated fields aren't "saved" -- they only display the value that
you calculate for them.

Can you post a simple code example that illustrates the problem? It
sounds like perhaps you don't completely understand how floating point
math works in a 32-bit  processor....

-- 
Nick Hodges -- TeamB
Dunn Solutions Group -- http://www.dunnsolutions.com
Read my Blog -- http://www.lemanix.com/nickblog
Re: Calc. fields in TClientDataSet.
#68
Author: Joaquin P.
Date: Thu, 12 Jan 2006 09:25
63 lines
3508 bytes
   Perhaps I didn't explain myself sufficiently clear. I know that 
calculated fields are used for displaying values (not for save them); I just 
wanted to say 'assigned', instead of 'saved'.
   Anyways, I'll show a code example (it's as simple as enigmatic).:
...
type
  TVentas2Fr = class(TForm)
...
    tbMemDocLin: TClientDataSet;
    tbMemDocLinPvp: TFloatField;            {FieldKind: fkData}
    tbMemDocLinUdsVenta: TFloatField;    {FieldKind: fkData}
    tbMemDocLinCalPvp: TFloatField;        {FieldKind: fkCalculated}
...
procedure TVentas2Fr.tbMemDocLinCalcFields(DataSet: TDataSet);
begin
    // Assign to 'CalPvp' the result of multiplying 'Pvp' and 'UdsVenta':
    tbMemDocLinCalPvp.Value := tbMemDocLinPvp.Value * 
tbMemDocLinUdsVenta.Value;
end;
...

    I'm showing the value assigned to 'CalPvp' in a TDBText component, 
called 'DBText1', on my form. Let's suppose some different cases:

a) tbMemDocLinPvp.Value := 4;  tbMemDocLinUdsVenta.Value := 8;
    In this case, DBText1 shows 0, instead of 32 .
b) tbMemDocLinPvp.Value := 4.1;  tbMemDocLinUdsVenta.Value := 8;
    DBText1 shows 32.8 (correct!).
c) tbMemDocLinPvp.Value := 5.5;  tbMemDocLinUdsVenta.Value := 3;
    DBText1 shows 0, instead of 16.5 .
d) tbMemDocLinPvp.Value := 5.6;  tbMemDocLinUdsVenta.Value := 3;
    DBText1 shows 16.8 (correct!).

     I hope that these lines can help to understand the nature of the 
problem, and to obtain a satisfactory solution.

    Thanks.

//
//
//

"Nick Hodges [TeamB]" <nickhodges@gmail.com> escribi� en el mensaje 
news:43c58e16$1@newsgroups.borland.com...
> Joaquin P. wrote:
>
>>  * Results of the calculation, having the decimal part '0' or '5'
>> (i.e. '24' or '15,5' -we use comma as decimal separator, but I tried
>> using decimal point with the same result-), are saved ALWAYS as '0'
>> in the calc. field.    * Results having any other decimal ('15,1',
>> '15,23', '32,70', '32.70', ...) are saved CORRECTLY.
>
> Calculated fields aren't "saved" -- they only display the value that
> you calculate for them.
>
> Can you post a simple code example that illustrates the problem? It
> sounds like perhaps you don't completely understand how floating point
> math works in a 32-bit  processor....
>
> -- 
> Nick Hodges -- TeamB
> Dunn Solutions Group -- http://www.dunnsolutions.com
> Read my Blog -- http://www.lemanix.com/nickblog 
Re: Calc. fields in TClientDataSet.
#69
Author: Joaquin P.
Date: Thu, 12 Jan 2006 09:31
23 lines
1854 bytes
Just remember I'm working in a Delphi-VCL.NET project with BDS2005 and 
Updates 1,2 & 3 installed.


"Joaquin P." <jpaton@proib.com> escribi� en el mensaje 
news:43c4ce3e@newsgroups.borland.com...
> Hi!
>
>    I'm using a TClientDataSet component in a VCL.NET application, and I've 
> defined several data and calculated fields.
>    Everything is running ok, but I noticed about a 'rare behaviour' of 
> calc. fields (TFloatField only):
>    * Results of the calculation, having the decimal part '0' or '5' (i.e. 
> '24' or '15,5' -we use comma as decimal separator, but I tried using 
> decimal point with the same result-), are saved ALWAYS as '0' in the calc. 
> field.
>    * Results having any other decimal ('15,1', '15,23', '32,70', '32.70', 
> ...) are saved CORRECTLY.
>
>    Please, can anybody help me?
>
>    Thanks.
> 
Re: Calc. fields in TClientDataSet.
#70
Author: Joaquin P.
Date: Thu, 12 Jan 2006 13:39
2 lines
1194 bytes
I've posted a full-code example at borland.public.attachments (Subject: 
Calc. fields in TClientDataSet: Full example). 
EUREKA!!!
#71
Author: Joaquin P.
Date: Thu, 12 Jan 2006 15:37
4 lines
1097 bytes
The solution: replace the value of the 'FieldKind' property, 'fkCalculated', 
by 'fkInternalCalc'.

Thanks, Ivan. 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads