Board index » delphi » ClientDataset: Virtual fields

ClientDataset: Virtual fields


2004-09-16 03:05:45 AM
delphi159
Hi!
In a ClientDataset I need a special (virtual) field, which is not included
in the dataset of the server, but it is calculated from another (real) field
and MUST NOT be read only. So I need a way to first calculate the virtual
field after getting the data data from the server dataset AND second modify
the real field base on a calculation with the virtual field.
In other words: The GUI needs a simple field for editing which does not
exists in the database.
I'm using in one datamodule: ClientDataset ->DatasetProvider ->
TpFIBDataset
I have tried some work with fkInternalCalc, but this does not work. And if I
add a normal field to the CDS, there is an exception while opening because
the field does not exist in the server dataset.
Hope someone can give me a hint...
Best regards,
Georg
 
 

Re:ClientDataset: Virtual fields

Author := "Georg Ledermann";
| I have tried some work with fkInternalCalc, but this does not work.
| And if I add a normal field to the CDS, there is an exception while
| opening because the field does not exist in the server dataset.
| Hope someone can give me a hint...
Use an aliased column that contains a constant expression in the SELECT
statement with a value appropriate for the datatype you want your
virtual field to be. For instance:
SELECT CUSTOMERS.*, '' AS VirtualColumn FROM CUSTOMERS
for a string field or
SELECT CUSTOMERS.*, 0 AS VirtualColumn FROM CUSTOMERS
for a numeric field. Unfortunately you cannot fully control the
datatype of the resulting field; that is up to the SQL engine of the
database. Usually these fields are given the maximum size for their
datatype.
Also, remember to clear the ProviderFlags property of this field so
that it will not participate in the update SQL statements when the
clientdataset is applied to the database. If you can turn off and then
back on the LogChanges property when you assign a value to that field
so that the change is not contained in the dataset's delta.
--
"If something hits the fan it is not distributed evenly."