Adding a calculated field to a Query at run time.

Posted by JamesB on Stack Overflow See other posts from Stack Overflow or by JamesB
Published on 2010-03-26T13:50:29Z Indexed on 2010/03/26 13:53 UTC
Read the original article Hit count: 307

Filed under:
|
|

I'm getting data using a query in Delphi, and would like to add a calculated field to the query before it runs. The calculated field is using values in code as well as the query so I can't just calculate it in SQL.

I know I can attach an OnCalcFields Event to actually make the calculation, but the problem is after adding the calculated field there are no other fields in the query...

I did some digging and found that all of the field defs are created but the actual fields are only created

if DefaultFields then
    CreateFields

Default Fields is specified

procedure TDataSet.DoInternalOpen;
begin
    FDefaultFields := FieldCount = 0;
    ...
end;

Which would indicate that if you add fields you only get the fields you added.

I would like all the fields in the query AS WELL AS the ones I Add.

Is this possible or do I have to add all the fields I'm using as well?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about query