Forum > LCL

How do I add a Pascal computed column in DBGrid?

(1/1)

petejones:
How do I add a Pascal computed column in DBGrid?

I have a complex calculation to make for a column and have to do it in Pascal (rather than SQL). Is there a grid event I can hook into that will allow this? OnDrawColumnCell perhaps?

Cheers
Pete

rvk:
Why not add the calculated column as TField to the dataset (DBGrid.Dataset)?

https://forum.lazarus.freepascal.org/index.php?topic=21006.0
https://lazarus.lazarus.freepascal.narkive.com/I7vozZ0F/can-t-create-calculated-field

petejones:
Yes that would do, thanks.

petejones:
How do I get round the read-only/not in edit mode issue?

I'm doing all this in code, so I set ReadOnly = False on the Query and the DataSet to Edit, but I still get an error: "DataSet is read-only"

rvk:

--- Quote from: petejones on May 21, 2022, 05:49:45 pm ---How do I get round the read-only/not in edit mode issue?

I'm doing all this in code, so I set ReadOnly = False on the Query and the DataSet to Edit, but I still get an error: "DataSet is read-only"

--- End quote ---
Why would you want to change a calculated field? It's calculated so it's read only by nature.

In TSQLQuery.OnCalcFields you can set the value with FieldByName('calc').asSomething := abc; to fill the value.
But you shouldn't send this to the server.

So where are you having trouble with a read-only field?
(otherwise show us a simple example)

Navigation

[0] Message Index

Go to full version