我看了FastReport的帮助手册和Dome ,上面实现主从表的关系是通过Table的属性 设置从表的mastsource来建立主从关系,就可以打印报表,但是没有说明二个query建立的主从关系报表怎样打印.下面是二个query建立的主从关系:query1的字段:card_id,card_num等(主表)
   query1.sql.text:='select * from table1'
query2的字段:card_id,card_name等(从表)
  query2.sql.text:='select * from table2 where card_id:=card_id'在query1的Query1AfterScroll事件中:
  begin
    query2.close;    
   query2.parambyname('card_id').value:=query1.fieldbyname('card_id).value;
    query2.open;
  end;现在的问题是怎样实现在FastReport 中打印两个query对组成的主从报表,或者其它报表控件?
----------------------
  主表记录1
     从表记录1
     从表记录2
     从表记录3
      .....
----------------------
  主表记录2
     从表记录1
     从表记录2
     从表记录3
      ...

解决方案 »

  1.   

    object frmBasicMD: TfrmBasicMD
      Left = 231
      Top = 180
      Width = 696
      Height = 480
      Caption = 'frmBasicMD'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      Scaled = False
      OnShow = FormShow
      PixelsPerInch = 96
      TextHeight = 13
      object QuickRep1: TQuickRep
        Left = 16
        Top = 0
        Width = 816
        Height = 1056
        Frame.Color = clBlack
        Frame.DrawTop = False
        Frame.DrawBottom = False
        Frame.DrawLeft = False
        Frame.DrawRight = False
        DataSet = tbCustomer
        Description.Strings = (
          'Basic Master/Detail report with grouping')
        Font.Charset = DEFAULT_CHARSET
        Font.Color = clWindowText
        Font.Height = -13
        Font.Name = 'Arial'
        Font.Style = []
        Functions.Strings = (
          'PAGENUMBER'
          'COLUMNNUMBER'
          'REPORTTITLE')
        Functions.DATA = (
          '0'
          '0'
          '''''')
        Options = [FirstPageHeader, LastPageFooter]
        Page.Columns = 1
        Page.Orientation = poPortrait
        Page.PaperSize = Letter
        Page.Values = (
          127
          2794
          127
          2159
          127
          127
          0)
        PrinterSettings.Copies = 1
        PrinterSettings.Duplex = False
        PrinterSettings.FirstPage = 0
        PrinterSettings.LastPage = 0
        PrinterSettings.OutputBin = Auto
        PrintIfEmpty = True
        SnapToGrid = True
        Units = Inches
        Zoom = 100
        object DetailBand1: TQRBand
          Left = 48
          Top = 71
          Width = 720
          Height = 17
          Frame.Color = clBlack
          Frame.DrawTop = False
          Frame.DrawBottom = False
          Frame.DrawLeft = False
          Frame.DrawRight = False
          AlignToBottom = False
          Color = clWhite
          ForceNewColumn = False
          ForceNewPage = False
          Size.Values = (
            44.9791666666667
            1905)
          BandType = rbDetail
          object QRDBText1: TQRDBText
            Left = 0
            Top = 0
            Width = 56
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              0
              0
              148.166666666667)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Color = clWhite
            DataSet = tbCustomer
            DataField = 'Company'
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
        end
        object QRSubDetail1: TQRSubDetail
          Left = 48
          Top = 106
          Width = 720
          Height = 18
          Frame.Color = clBlack
          Frame.DrawTop = False
          Frame.DrawBottom = False
          Frame.DrawLeft = False
          Frame.DrawRight = False
          AlignToBottom = False
          Color = clWhite
          ForceNewColumn = False
          ForceNewPage = False
          Size.Values = (
            47.625
            1905)
          Master = QuickRep1
          DataSet = qryOrders
          FooterBand = QRBand1
          PrintBefore = False
          PrintIfEmpty = True
          object QRDBText2: TQRDBText
            Left = 232
            Top = 0
            Width = 49
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              613.833333333333
              0
              129.645833333333)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Color = clWhite
            DataSet = qryOrders
            DataField = 'OrderNo'
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
          object QRDBText4: TQRDBText
            Left = 386
            Top = 0
            Width = 61
      

  2.   

    Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              1021.29166666667
              0
              161.395833333333)
            Alignment = taRightJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Color = clWhite
            DataSet = qryOrders
            DataField = 'ItemsTotal'
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
        end
        object QRGroup1: TQRGroup
          Left = 48
          Top = 88
          Width = 720
          Height = 18
          Frame.Color = clBlack
          Frame.DrawTop = False
          Frame.DrawBottom = False
          Frame.DrawLeft = False
          Frame.DrawRight = False
          AlignToBottom = False
          Color = clWhite
          ForceNewColumn = False
          ForceNewPage = False
          Size.Values = (
            47.625
            1905)
          Expression = 'qryOrders.Terms'
          Master = QRSubDetail1
          ReprintOnNewPage = False
          object QRDBText3: TQRDBText
            Left = 128
            Top = 0
            Width = 37
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              338.666666666667
              0
              97.8958333333333)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Color = clWhite
            DataSet = qryOrders
            DataField = 'Terms'
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
        end
        object ColumnHeaderBand1: TQRBand
          Left = 48
          Top = 48
          Width = 720
          Height = 23
          Frame.Color = clBlack
          Frame.DrawTop = False
          Frame.DrawBottom = False
          Frame.DrawLeft = False
          Frame.DrawRight = False
          AlignToBottom = False
          Color = clWhite
          Font.Charset = DEFAULT_CHARSET
          Font.Color = clWindowText
          Font.Height = -13
          Font.Name = 'Arial'
          Font.Style = [fsBold, fsUnderline]
          ForceNewColumn = False
          ForceNewPage = False
          ParentFont = False
          Size.Values = (
            60.8541666666667
            1905)
          BandType = rbColumnHeader
          object QRLabel1: TQRLabel
            Left = 0
            Top = 0
            Width = 61
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              0
              0
              161.395833333333)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Caption = 'Company'
            Color = clWhite
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
          object QRLabel2: TQRLabel
            Left = 128
            Top = 0
            Width = 40
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              338.666666666667
              0
              105.833333333333)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Caption = 'Terms'
            Color = clWhite
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
          object QRLabel3: TQRLabel
            Left = 232
            Top = 0
            Width = 91
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              613.833333333333
              0
              240.770833333333)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Caption = 'Order Number'
            Color = clWhite
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
          object QRLabel4: TQRLabel
            Left = 376
            Top = 0
            Width = 71
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              994.833333333333
              0
              187.854166666667)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Caption = 'Items Total'
            Color = clWhite
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
          object QRLabel5: TQRLabel
            Left = 480
            Top = 0
            Width = 97
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              1270
              0
              256.645833333333)
            Alignment = taLeftJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Caption = 'Customer Total'
            Color = clWhite
            Transparent = False
            WordWrap = True
            FontSize = 10
          end
        end
        object QRBand1: TQRBand
          Left = 48
          Top = 124
          Width = 720
          Height = 21
          Frame.Color = clBlack
          Frame.DrawTop = False
          Frame.DrawBottom = False
          Frame.DrawLeft = False
          Frame.DrawRight = False
          AlignToBottom = False
          Color = clWhite
          ForceNewColumn = False
          ForceNewPage = False
          Size.Values = (
            55.5625
            1905)
          BandType = rbGroupFooter
          object QRExpr1: TQRExpr
            Left = 416
            Top = 0
            Width = 159
            Height = 17
            Frame.Color = clBlack
            Frame.DrawTop = False
            Frame.DrawBottom = False
            Frame.DrawLeft = False
            Frame.DrawRight = False
            Size.Values = (
              44.9791666666667
              1100.66666666667
              0
              420.6875)
            Alignment = taRightJustify
            AlignToBand = False
            AutoSize = True
            AutoStretch = False
            Color = clWhite
            Master = QRSubDetail1
            ResetAfterPrint = True
            Transparent = False
            WordWrap = True
            Expression = 'SUM(qryOrders.ItemsTotal)'
            Mask = '$,###.00'
            FontSize = 10
          end
        end
      end
      object dsCustomer: TDataSource
        DataSet = tbCustomer
        Left = 24
      end
      object tbCustomer: TTable
        Active = True
        DatabaseName = 'DBDEMOS'
        IndexFieldNames = 'Company'
        TableName = 'CUSTOMER.DB'
        Left = 24
        Top = 32
      end
      object qryOrders: TQuery
        Active = True
        DatabaseName = 'DBDEMOS'
        DataSource = dsCustomer
        SQL.Strings = (
          'select * from orders '
          'WHERE (CustNo = :CustNo)'
          'order by custno, Terms')
        Left = 24
        Top = 56
        ParamData = <
          item
            DataType = ftFloat
            Name = 'CustNo'
            ParamType = ptUnknown
            Size = 8
          end>
      end
    end
      

  3.   

    把这个from 加入一个工程,你再运行.就能看到效果了