procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
x: Integer;
TheField : String;
begin
x := Column.Index;
TheField := Query1.Fields[x].FieldName;
with Query1do
begin
Active := FALSE;
Sql.Clear;
Sql.Add('Select * from employee order by '+TheField);
Active := TRUE;
end;
end;