1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
procedure TriColonneSql(Column: TColumn;Ordre :String);
var
ligne :integer;
rq :Tquery;
Trouve: boolean;
begin
if column.FieldName='' then exit;
if column.Field.DataSet=Nil then exit;
rq := TQuery(column.Field.DataSet);
if (rq.State = dsBrowse) or (rq.State= dsInactive) then
begin
if ordre='' then
ordre := column.FieldName;
ligne := 0;
Trouve := False;
// determine le numero de ligne
repeat
inc(ligne);
if pos('ORDER BY',UpperCase(rq.SQl.strings[ligne]))<>0 then
begin
Trouve := True;
break;
end;
until ligne=rq.SQL.count-1;
if Trouve then
begin
if (pos(ordre,UpperCase(rq.SQl.strings[ligne]))<>0) and
(pos('DESC',UpperCase(rq.SQl.strings[ligne]))=0) then
begin
if (pos(',',Ordre)<>0) then
ordre := copy(Ordre,1,pos(',',Ordre)-1)+ ' DESC '
+ copy(Ordre,pos(',',Ordre),length(ordre))
else
ordre := ordre + ' DESC';
rq.SQl.strings[ligne] := 'ORDER BY '+Ordre;
end
else
rq.SQl.strings[ligne] := 'ORDER BY '+Ordre;
end
else
rq.SQL.Add('ORDER BY '+ordre);
end;
end; |
Partager