Board index » delphi » TQuery component with calculated fields created in runtime

TQuery component with calculated fields created in runtime

I create a TQuery component while running my program because it is not needed
for every execution. That's no problem.

My problem is to add a calculated field in runtime.

I have created a SELECT statement as follows:

SELECT DATUM, ANFANG, DAUER, ZIELNR, EINHEITEN, FREMD, :BEinheiten
FROM "TELERECH.DBF"
WHERE (DATUM >= :FirstDay ) AND (DATUM <= :LastDay)

(The query worked correctly since it didn't contain the field BEinheiten)

Then I add a TFieldDef for the field BEinheiten before Executing the methods
TQuery.Prepare and TQuery.Open. (Else I get the message that the field
BEinheiten was unknown.) I set the properties DataType of the new TField and
TFieldDef to ftInteger. TQuery.OnCalcFields is pointed to a method that
contains the statement

Query.FieldByName('BEinheiten').AsInteger := 0;
(Query is a field of the Form containing the method. Its type is TQuery.)

I get the message that the field type is unknown. Where is the mistake?

Hoping for help
Andreas
Internet: http://members.aol.com/AJakobsche/

 

Re:TQuery component with calculated fields created in runtime


Quote
AJakobsche wrote:
> My problem is to add a calculated field in runtime.

> I have created a SELECT statement as follows:

> SELECT DATUM, ANFANG, DAUER, ZIELNR, EINHEITEN, FREMD, :BEinheiten
> FROM "TELERECH.DBF"
> WHERE (DATUM >= :FirstDay ) AND (DATUM <= :LastDay)

Anything between the select and the from has to be answered from the
database. No parameters are allowed there.

If you want a value which is always the same, you can code:
SELECT FIELD1, 5 FROM ...
If you want a calculated value, code
SELECT FIELD1, 5*Field1 FROM ...

HTH

Other Threads