Board index » delphi » Can I use a run-time Calculated Field in a TQuery

Can I use a run-time Calculated Field in a TQuery

Hello,

    I'm using Delphi to solve a problem in which a data field needs to
be calculated
and I'm only allowed to use Paradox as a database so I cannot do stored
procedures.  The field cannot be calculated on the query so I need a
calculated field.

    I have been trying to create a calculated field at run-time, for the
TQuery, just before the query is executed, but I have not been
successful.  I get errors that indicate that "the field does not have a
dataset".

Can anyone help?

Regards

- Harry

 

Re:Can I use a run-time Calculated Field in a TQuery


you can do it in design-time,
right click your query->fields editor->right click->new field
give it a name , type..., and choose calculated

in OnCalcFields of your query, assign a value to that field

Quote
Harry Morin wrote:

> Hello,

>     I'm using Delphi to solve a problem in which a data field needs to
> be calculated
> and I'm only allowed to use Paradox as a database so I cannot do stored
> procedures.  The field cannot be calculated on the query so I need a
> calculated field.

>     I have been trying to create a calculated field at run-time, for the
> TQuery, just before the query is executed, but I have not been
> successful.  I get errors that indicate that "the field does not have a
> dataset".

> Can anyone help?

> Regards

> - Harry

Re:Can I use a run-time Calculated Field in a TQuery


Quote
Harry Morin <hmo...@amano.com> wrote:
>Hello,>
>    I'm using Delphi to solve a problem in which a data field needs to
>be calculated
>and I'm only allowed to use Paradox as a database so I cannot do stored
>procedures.  The field cannot be calculated on the query so I need a
>calculated field.

>    I have been trying to create a calculated field at run-time, for the
>TQuery, just before the query is executed, but I have not been
>successful.  I get errors that indicate that "the field does not have a
>dataset".

>Can anyone help?

>Regards

>- Harry

Hello Harry
rightclick your TQuery component and open the field editor,
then rightclick the field editor and choose "add all fields"
(if your query contains parameters replace them by constants
before you do that and later insert your parameters again)
After you have added the fields choose "new field" in the
field editor and record your calculated field.
Greetings Edi

Re:Can I use a run-time Calculated Field in a TQuery


Quote
>Harry Morin wrote:

> I have been trying to create a calculated field at run-time, for the
> TQuery, just before the query is executed, but I have not been
> successful.  I get errors that indicate that "the field does not have > a dataset".

Forgot to set the DataSet property of the newly created field?
  ..
  Query1.Close;
  fld := TStringField.Create(Query1);
  fld.FieldName := 'Calc';
  ..
  fld.DataSet := Query1;
  Query1.FieldDefs.Update;
  Query1.Open;
________
Andreas
Delphi 5.01 Pro, NT4.0 Sp5
Direct replies mailto:p...@augsburg.netsurf.de

Other Threads