Recent

Author Topic: How do I add a Pascal computed column in DBGrid?  (Read 916 times)

petejones

  • New Member
  • *
  • Posts: 13
How do I add a Pascal computed column in DBGrid?
« on: May 21, 2022, 12:42:51 am »
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

  • Hero Member
  • *****
  • Posts: 6110
« Last Edit: May 21, 2022, 01:03:17 am by rvk »

petejones

  • New Member
  • *
  • Posts: 13
Re: How do I add a Pascal computed column in DBGrid?
« Reply #2 on: May 21, 2022, 01:06:26 am »
Yes that would do, thanks.

petejones

  • New Member
  • *
  • Posts: 13
Re: How do I add a Pascal computed column in DBGrid?
« Reply #3 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"

rvk

  • Hero Member
  • *****
  • Posts: 6110
Re: How do I add a Pascal computed column in DBGrid?
« Reply #4 on: May 22, 2022, 05:40:11 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"
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)

 

TinyPortal © 2005-2018