How to get list of fields from all objects of the currently active sub-query (VCL Edition)?
Last modified:
Below is the code sample of getting the list of fields from all objects in the currently active sub-query. This list is identical to the content of drop-down in the inline editor for Expression column in the Query Columns Grid.
procedure TForm1.ButtonClick(Sender: TObject);
var
availableFields: TStringList;
usq: TacUnionSubQuery;
datasourceList: TObjectList;
i,j: integer;
datasource: TacDatasource;
datasourceNameInQuery: WideString;
fieldName: WideString;
field: TacMetadataField;
begin
usq := queryBuilder.ActiveSubQuery.ActiveUnionSubquery;
availableFields := TStringList.Create;
datasourceList := TObjectList.Create(false);
try
// get list of all datasources
usq.FromClause.GetDatasources(datasourceList);
for i:=0 to datasourceList.Count-1 do
begin
datasource := TacDatasource(datasourceList[i]);
datasourceNameInQuery := datasource.NameInQuery;
for j:=0 to datasource.Fields.Count-1 do
begin
field := datasource.Fields[j];
fieldName := '';
if queryBuilder.UseAltNames and (field.AltName <> '')
then fieldName := field.AltNameId.SimpleSQL(queryBuilder.SQLContext.SQLBuilderExpression);
if fieldName='' then fieldName := field.Name.QualifiedName;
availableFields.Add(datasourceNameInQuery+'.'+fieldName);
end;
end;
ShowMessage(availableFields.Text);
finally
datasourceList.Free;
availableFields.Free;
end;
end;