stringgird中使用TClientDataSet排序的问题

function TfrmMain.createIIReport(cdsBody: TClientDataSet;
  silent: Boolean): String;
var
    s,sText: String;
    i: Integer;
    sTail: String;
    sSpace: String;
begin
  try
    try
      sTail := #13#10;
      sSpace := ' ';
      sText := '<?xml version="1.0" encoding="GBK"?>' + sTail;
      cdsBody.DisableControls;
      cdsBody.Filtered := false;
      cdsBody.IndexFieldNames := '顺序';

      cdsBody.First;
      while not cdsBody.Eof do
      begin
        s := '';
        for i := 1 to cdsBody.FieldByName('indent').AsInteger do
          s := s + sSpace;
        if cdsBody.FieldByName('KIND').AsString = '1' then
          s := s + cdsBody.FieldByName('tag').AsString
        else
        begin
          s := s +  '<' + cdsBody.FieldByName('TAG').AsString + '>' +
              cdsBody.FieldByName('默认值').AsString + '</' + cdsBody.FieldByName('TAG').AsString + '>';
        end;
        sText := sText + s + sTail;
        cdsBody.Next;
      end;
      Result := sText;
    except
      Result := '';
    end;
  finally
    cdsBody.Filter := 'kind = 0';
    cdsBody.Filtered := True;
    cdsBody.EnableControls;
  end;

原文地址:https://www.cnblogs.com/batman425/p/3141673.html