Calculated fields

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jdorlon
Posts: 202
Joined: Fri 05 Jan 2007 22:07

Calculated fields

Post by jdorlon » Tue 27 Jan 2009 18:32

Hello,

I added this code in the BeforeOpen event of my TSmartQuery. The field was created, but the TSmartQuery did not create fields for any of columns of the query. Is there a way to add Calculated Fields in TSmartQuery?

Thanks,

John D.

Field := TIntegerField.Create(qrydata);
Field.FieldName := 'RecNo';
Field.Calculated := True;
Field.Dataset := qrydata;
qryData.OnCalcFields := DataSetCalcFields;

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Wed 28 Jan 2009 08:26

You should create data fields first. Use the following code to create data fields:

Code: Select all

  OraQuery1.FieldDefs.Update;

  // copied from DB unit
  if OraQuery1.ObjectView then
  begin
    for I := 0 to OraQuery1.FieldDefs.Count - 1 do
      with OraQuery1.FieldDefs[I] do
        if (DataType  ftUnknown) and
          not ((faHiddenCol in Attributes) and not OraQuery1.FIeldDefs.HiddenFields) then
          CreateField(Self);
  end else
  begin
    for I := 0 to OraQuery1.FieldDefList.Count - 1 do
      with OraQuery1.FieldDefList[I] do
        if (DataType  ftUnknown) and not (DataType in ObjectFieldTypes) and
          not ((faHiddenCol in Attributes) and not OraQuery1.FIeldDefs.HiddenFields) then
          CreateField(Self, nil, OraQuery1.FieldDefList.Strings[I]);
  end;

jdorlon
Posts: 202
Joined: Fri 05 Jan 2007 22:07

Post by jdorlon » Wed 28 Jan 2009 22:00

That did it, thank you!

Post Reply