我想查询某一门课程的成绩,并加以打印。
打印字段有:学号、姓名、成绩、补考成绩。查询结果测试正确。按钮“查询”的事件为:打开MainForm,是打印窗口
其中有个DBGrid,里面为ADOQuery的结果。代码如下:
procedure Tf_main.b_print_scoreClick(Sender: TObject);
begin
  with MainForm do
  begin
    i_header.Text:='成绩单:'+o_course_name.Text; //设置打印标题
    adodm.Q_print_contents.Close;
    adodm.Q_print_contents.SQL.Clear;
    adodm.Q_print_contents.SQL.Add('select 学号,姓名,成绩,补考成绩 from score'+
                                   ' where 课程代码 ='''+i_course_id.Text+'''');
    adodm.Q_print_contents.Open;
    StringGrid1.RowCount:=4;
    //设置各栏的列标题和列宽
    StringGrid1.Cells[0,0]:='学号';
    StringGrid1.Cells[1,0]:='10';
    StringGrid1.Cells[0,1]:='姓名';
    StringGrid1.Cells[1,1]:='15';
    StringGrid1.Cells[0,2]:='成绩';
    StringGrid1.Cells[1,2]:='20';
    StringGrid1.Cells[0,3]:='补考成绩';
    StringGrid1.Cells[1,3]:='10';
    ShowModal;
    end;
end;弹出的MainFrm可以在DBGrid里看到正确的结果,不过点击打印后。结果4个字段显示的都是每条记录的学号。不知道哪里出错了??procedure TMainForm.B_printClick(Sender: TObject);
var
  Items: TStringList;
  i:integer;
begin
  //Items用于保存打印一行的格式信息
  Items := TStringList.Create;
  try
    //确定水平方向每inch的像素数
    PixelsInInchx := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
    TenthsOfInchPixelsY := GetDeviceCaps(Printer.Handle,
                            LOGPIXELSY) div 10;
    AmountPrinted := 0;
    MainForm.Enabled := false; // 主打印窗体无效
    try
      Printer.BeginDoc;
      AbortForm.Show;
      Application.ProcessMessages;
      //用当前字体计算一行文本的高度
      LineHeight := Printer.Canvas.TextHeight('X')+TenthsOfInchPixelsY;
      if i_header.Text <> '' then
        PrintHeader;
      PrintColumnNames;
      adodm.Q_print_contents.First;
      //将每行内容和宽度保存在Items中
      while (not adodm.Q_print_contents.Eof) or Printer.Aborted do
      begin        Application.ProcessMessages;
        with Items do
        begin
          for i:=0 to adodm.Q_print_contents.FieldCount-1 do
          begin
            AddObject(adodm.Q_print_contents.Fields[0].AsString,
                        pointer(StrToInt(StringGrid1.Cells[1,i])));
          end;//我不知道哪里出了问题了
        end;
end;*********代码比较多,请高手们耐心一点了,拜托*********