Could not convert variant of type (Array Byte) into type (Double)

Getting the above error on my server and am having trouble understanding why. I’m using XE6 with MSSQL via FireDAC.

I have a datatable which contains three DECIMAL(19,4) fields. These come through into my strongly-typed classes/interfaces as Double type functions and properties.

The above error is being thrown in my server-side validation logic which is running in the BeforeProcessChange event of my business processor. Within this handler, it appears that I can access the first of these three decimal fields without problem using the strongly-typed properties, but if I try to access the value of the other two, I get the above error, as if it’s failing to convert it to a double value correctly. All other fields are fine too.

Can anyone please shed some light on this as it’s a show-stopper and makes no sense to me at all.

UPDATE: On further investigation, it appears that the one field which works fine has a NULL value, which is correctly coming up as zero in the strongly-typed double property. The other two fields have zero values in them and these are the ones which throw the error when accessed.

Is this something to do with the exact type of decimal field I’m using? For the record this is an MSSQL Server decimal(19,4) data type. It comes into the schema as a Decimal type field and I’ve set the Scale/Precision to 4/19 respectively.

can you create a simple testcase that reproduces this case, pls?
also include DDL script for creating required table

I’ll have a go at this tomorrow

I’ve reproduced this in a simple test case which I’ve sent to support@remobjects.com
There’s also an SQL script in there to create the database.

Basically there’s a single table with a DECIMAL(19,4) field in it. The client has a button which just appends a new record to this table. This works fine until I implement some business logic in SchemaServer.pas which uses the strongly typed interface to access the field and check the value. This then fails with the originally reported error.

open uDASchemaUnitsGenerator.pas and uncomment

// usage TBCD instead of Double for datDecimal
{.$DEFINE TREAT_DECIMAL_AS_TBCD}

after this recompile DA_IDE package

Ok thanks I’ll give that a try.

What’s the underlying reason here by the way? Do different versions of Delphi or different databases need to use Double rather than TBCD?

AFAIR, TBCD isn’t such flexible that double. probably we need to use this define by default

I’ve just been caught out by this as I’d forgotten to re-implement this change when last upgrading.

As this is a configuration setting rather than a bug, am I right in assuming I’m going to need to remember to re-do it every time I upgrade DA? Isn’t there a better way of doing this?

After upgrading to the latest release, I notice this define is still commented out. Is this intentional or was the decision to enable it by default overlooked?

done. now it will be enabled by default