dataset中存放的是已经从数据库中取出并排好序的数据,然后将这些数据放到Tstrings中(怎么往里赋值),再将这些数据用另一种排序方式(也就是根据数据中的其他字段排序)排序,然后打印。(整个过程不能重新取数据库,只能用dataset中已经取出的数据)请问,这该怎么实现,以前没怎么用过Tstrings这种类型。请高手指点!谢谢!

解决方案 »

  1.   

    procedure TFormNewBuildingStat.frReportNewBuildingGetValue(
      const ParName: String; var ParValue: Variant);
    begin
      inherited;
      if AnsiCompareText(ParName, 'Cell1') = 0 then
        ParValue := StringGrid1.Cells[0, frUserDataset1.RecNo+1]
      else if AnsiCompareText(ParName, 'Cell2') = 0 then
        ParValue := StringGrid1.Cells[1, frUserDataset1.RecNo+1]
      else if AnsiCompareText(ParName, 'Cell3') = 0 then
        ParValue := StrToFloat(StringGrid1.Cells[2, frUserDataset1.RecNo+1])
      else if AnsiCompareText(ParName, 'Cell4') = 0 then
        ParValue := StrToFloat(StringGrid1.Cells[3, frUserDataset1.RecNo+1])
      else if AnsiCompareText(ParName, 'Cell5') = 0 then
        ParValue := StrToFloat(StringGrid1.Cells[4, frUserDataset1.RecNo+1])
      else if AnsiCompareText(ParName, 'Cell6') = 0 then
        ParValue := StrToFloat(StringGrid1.Cells[5, frUserDataset1.RecNo+1])
      else if AnsiCompareText(ParName, 'Cell7') = 0 then
        ParValue := StrToFloat(StringGrid1.Cells[6, frUserDataset1.RecNo+1])
      else if AnsiCompareText(ParName, 'Cell8') = 0 then
        ParValue := StrToFloat(StringGrid1.Cells[7, frUserDataset1.RecNo+1])
      else if AnsiCompareText(ParName, 'Cell9') = 0 then
        ParValue := StrToFloat(StringGrid1.Cells[8, frUserDataset1.RecNo+1])
      else if AnsiCompareText(ParName, 'CellYear') = 0 then
      begin
        if self.cbYear.Text='' then
          ParValue :='所有'
        else
          ParValue :=self.cbYear.Text;
      end;
    end;
      

  2.   

    procedure TFormNewBuildingStat.cmdPrintNewBuildingClick(Sender: TObject);
    begin
      inherited;
      self.frUserDataset1.RangeEnd:=reCount;
      self.frUserDataset1.RangeEndCount:=self.StringGrid1.RowCount-1;
      self.frReportNewBuilding.ShowReport;
    end;
      

  3.   

    with self.NewBuildingStat.DataView do
      begin
        first;
        for i:=1 to RecordCount do
        begin
          with self.StringGrid1 do
          begin
            Cells[0,i]:=IntToStr(i);
            Cells[1,i]:=FieldByName('C_Building_Name').AsString;
            Cells[2,i]:=FieldByName('C_Build_Area').AsString;
            Cells[3,i]:=FieldByName('C_Heating_Area').AsString;
            Cells[4,i]:=FieldByName('C_ShouldPay_Money').AsString;
            Cells[5,i]:=FieldByName('C_FactPay_Money').AsString;
            Cells[6,i]:=FieldByName('C_Goods_Money').AsString;
            Cells[7,i]:=FieldByName('C_Free_Money').AsString;
            Cells[8,i]:=FieldByName('C_Arrear').AsString;
            RowCount:=RowCount+1;
          end;
          next;
        end;
      end;