HomeActive Query BuilderFieldType of Expression

FieldType of Expression


AQB VCL Version - MS SQL Server

I am trying to get the field type of the selected columns in the grid.

For normal columns, it's fine; in OnGridCellChanging I just use

Sender.QueryStatistics.OutputColumns[ARow - 1].FieldType

However, this returns a type ftUnknown for expressions.

What I ideally want to get is the field type returned by the expression.

At present, I do the following:

If the expression is "Count", "ChkSum_Agg", "STDev" or "Var", then a numeric value is returned; otherwise it's the fieldtype of the underlying datafield.

So, I get the fieldname from the ASelectItem.ExpressionString then iterate through the QueryStatistics.UsedDatabaseObjectColumns to find the MetadataField.NameStr which matches, then get its fieldtype.

<code>
// find the field number in the used objects
FieldNo := -1;
for I := 0 to Sender.QueryStatistics.UsedDatabaseObjectColumns.Count - 1 do
begin
if UpperCase(FieldName) = UpperCase(Sender.QueryStatistics.UsedDatabaseObjectColumns[I].MetadataField.NameStr) then
begin
FieldNo := I;
Break;
end;
end; // for
if FieldNo >= 0 then
begin
WantedFieldType := Sender.QueryStatistics.UsedDatabaseObjectColumns[FieldNo].FieldType
end;
</code>

Is there an easier way to get to the returned fieldtype, without needing to loop through the UsedDatabaseObjectColumns collection?

Thanks,
... Joe
Joe Griffin | email
September 6 2011, 03:53 AM
Dear Joe,

There's no way to get type of expression. You may get the type by means of AQB only if expression is a single field.
Sergey Smagin | email
51 mins since original post
OK; Thanks Sergey.

Looks like the way I'm doing it is the way to go.

Thanks,
... Joe
Joe Griffin | email
1 hour, 58 mins since original post
This topic is closed