Subject Re: Actual field names
Author russellbelding
A pragmatic solution to my need is below:

--- In IBObjects@yahoogroups.com, "russellbelding" <russell@...> wrote:
>
> I have an "SQL script presenter" that presents in a TIB_GRID the data
> arriving from an SQL script fed to a TIB_QUERY. I want to allow the
> grid columns to be ordered by clicking on the column titles.
>
> Using a script like "select field01 from table" there is no problem.
I
> use grid.gridFields to get fields names like "field01" and feed these
> into the ordering properties of the query.
>
> Using a script like "select field01 as alias01 from table",
> I need "field01" for the query ordering properties. So far I can
> find "alias01" and have not found "field01". Any suggestions as to
how
> to find "field01" from the existing grid or query properties or
> methods?
> Thanks
>

Allow any col to be sorted in ascending or descending order by
reloading the data.

procedure TfrmResearch.gridSQLResultsTitleClick(Sender: TObject; ACol,
ARow: Integer; AButton: TMouseButton; AShift: TShiftState);
var
SQLStr, AD : string;
IOrder : integer;
begin
OrderCol := Acol;
if ssShift in AShift then AD := ' DESC' else AD := '';
with qrSQLResults do
begin
IOrder := pos('ORDER',uppercase(SQL.text));
If IOrder > 0 then SQLStr := copy(SQL.text,1,Iorder-1)
else SQLStr := SQL.text;
SQLStr := SQLStr+' order by '+inttostr(ACol)+AD;
Active := false;
SQL.Text := SQLStr;
Prepare;
Active := true;
end;
end;

procedure TfrmResearch.gridSQLResultsGetCellProps(Sender: TObject; ACol,
ARow: Integer; AState: TGridDrawState; var AColor: TColor; AFont:
TFont);
begin
if (OrderCol > 0) and (ACol>0) and (ARow>0 )then
if Acol=OrderCol then AColor := clInfoBK else AColor := clWindow;
end;