今天看到一个不使用设计器创建RAVE的例子,就贴出来给那些用RAVE的兄弟作个参考
Unit Unit1;InterfaceUses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  DB, Dialogs, StdCtrls, Buttons, Math, ApoDSet,
  RpBase, RpCon, RpConDS, RpDefine, RpDevice, RpRave, RpSystem,
  RvClass, RvCsData, RvCsDraw, RvCsStd, RvCsRpt, RvData, RvDefine, RvDirectDataView, RvUtil;Type
  TForm1 = Class(TForm)
    ApolloTable1: TApolloTable;
    btnClose: TBitBtn;
    btnReport: TButton;
    DataSource1: TDataSource;
    RvDataSetConnection1: TRvDataSetConnection;
    RvProject1: TRvProject;
    RvSystem1: TRvSystem;
    Procedure btnReportClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  End;Var
  Form1: TForm1;Implementation{$R *.dfm}Procedure TForm1.btnReportClick(Sender: TObject);
Var
  MyBand, MyTitleBand: TRaveBand;
  MyDataBand: TRaveDataBand;
  MyDataCnx: TRaveDataConnection;
  MyDataText: TRaveDataText;
  MyDataView: TRaveDataView;
  MyLine: TRaveHLine;
  MyPage: TRavePage;
  MyRegion: TRaveRegion;
  MyText: TRaveText;
  nMarginBottom, nMarginLeft, nMarginRight, nMarginTop: Double;
  // I1: integer;
Begin
  // Select the project file
  // RvProject1.ProjectFile := 'Project1.rav';
  // RvProject1.Open;
  //     OR
  RvProject1.New;  // 1 - use a blank page "Page 1 in Report 1" ======================
  MyPage := RvProject1.ProjMan.FindRaveComponent('Report1.Page1', Nil) As TRavePage;
  MyPage.WasteFit := True;
  // Set all margins to 搘aste?or 0.5 which ever is greater
  nMarginBottom := MaxValue([RpDev.Waste.Bottom / RpDev.YDPI, 0.5]);
  nMarginLeft := MaxValue([RpDev.Waste.Left / RpDev.XDPI, 0.5]);
  nMarginRight := MaxValue([RpDev.Waste.Right / RpDev.XDPI, 0.5]);
  nMarginTop := MaxValue([RpDev.Waste.Top / RpDev.YDPI, 0.5]);  // If you need to Delete all components on the page
  //for I1 := MyPage.ComponentCount - 1 downto 0 do begin
  //  MyPage.Components[I1].Free;
  //end;  .

解决方案 »

  1.   

    // 2 - Create DataView using Connection ===========================
      MyDataCnx := CreateDataCon(RvDatasetConnection1);
      MyDataView := RvProject1.ProjMan.NewDataObject(TRaveDataView) As TRaveDataView;
      MyDataView.ConnectionName := MyDataCnx.Name;
      MyDataView.DataCon := MyDataCnx;
      CreateFields(MyDataView, Nil, Nil, true);
      // 2a - place 揚age Number?directly ON the page NOT a band
      MyDataText := MyPage.CreateChild(TRaveDataText, 'dtPage') As TRaveDataText;
      MyDataText.DataField := '"Page of " + Report.CurrentPage + " of " + Report.TotalPages';
      MyDataText.FontJustify := pjRight;
      MyDataText.Width := 2; // Width MUST be before LEFT assignment
      MyDataText.Left := MyPage.PageWidth - nMarginRight - MyDataText.Width;
      MyDataText.Top := nMarginTop;
      // 2b - place 揇ate?directly ON the page NOT a band
      MyDataText := MyPage.CreateChild(TRaveDataText, 'dtDate') As TRaveDataText;
      MyDataText.DataField := 'Report.DateLong';
      MyDataText.FontJustify := pjRight;
      MyDataText.Width := 2; // Width MUST be before LEFT assignment
      MyDataText.Left := MyPage.PageWidth - nMarginRight - MyDataText.Width;
      MyDataText.Top := nMarginTop + 0.2;  // 3 - create a region and set it's properties ====================
      MyRegion := TRaveRegion.Create(MyPage);
      MyRegion.Left := nMarginLeft;
      MyRegion.Name := 'Region1';
      MyRegion.Parent := MyPage;
      MyRegion.Top := nMarginTop + 0.4; // Top MUST be before HEIGHT assignment
      MyRegion.Width := MyPage.PageWidth - (nMarginLeft + nMarginRight);
      MyRegion.Height := MyPage.PageHeight - (MyRegion.Top + nMarginBottom);  // 4 - Create Databand named "DetailBand" First (controller) ======
      MyDataBand := MyRegion.CreateChild(TRaveDataBAnd, 'DetailBand') As TRaveDataBand;
      MyDataBand.DataView := MyDataView; // Always set the band dataview property
      // 4a - Place DataText components in "DetailBand" just created
      MyDataText := MyDataBand.CreateChild(TRaveDataText, 'dtName') As TRaveDataText;
      // concatenate fields with comma between them
      MyDataText.DataField := 'Last' + ' + ", " + ' + 'First';
      MyDataText.DataView := MyDataView;
      MyDataText.FontJustify := pjLeft;
      MyDataText.Left := MyPage.PageLeft + 0.2;
      MyDataText.Top := 0.01;
      MyDataText.Width := 2;
      // 4b
      MyDataText := MyDataBand.CreateChild(TRaveDataText, 'dtStreet') As TRaveDataText;
      MyDataText.DataField := 'Street';
      MyDataText.DataView := MyDataView;
      MyDataText.FontJustify := pjLeft;
      MyDataText.Left := MyPage.PageLeft + 2.1;
      MyDataText.Top := 0.01;
      MyDataText.Width := 2;
      // 4c
      MyDataText := MyDataBand.CreateChild(TRaveDataText, 'dtCityStZip') As TRaveDataText;
      // concatenate fields with space between them
      MyDataText.DataField := 'City' + ' & ' + 'State' + ' & ' + 'Zip';
      MyDataText.DataView := MyDataView;
      MyDataText.FontJustify := pjLeft;
      MyDataText.Left := MyPage.PageLeft + 4.1;
      MyDataText.Top := 0.01;
      MyDataText.Width := 2;  // 5 - Create Header Band controlled by "DetailBand" ==============
      MyBand := MyRegion.CreateChild(TRaveBand, 'HeaderBand') As TRaveBand;  //      BandStyle Print Location codes
      // BandStyle PrintLoc b plBodyFooter
      // BandStyle PrintLoc g plGroupFooter
      // BandStyle PrintLoc r plRowFooter
      // BandStyle Printloc D plDetail
      // BandStyle Printloc R plRowHeader
      // BandStyle Printloc G plGroupHeader
      // BandStyle Printloc B plBodyHeader
      MyBand.BandStyle.PrintLoc := MyBand.BandStyle.PrintLoc + [plBodyHeader];  //      BandStyle Print Occurrence codes
      // BandStyle PrintOcc C poNewColumn
      // BandStyle PrintOcc P poNewPage
      // BandStyle PrintOcc 1 poFirst
      MyBand.BandStyle.PrintOcc := MyBand.BandStyle.PrintOcc + [poFirst, poNewPage];  MyBand.ControllerBand := MyDataBand;
      MyBand.Height := 0.2;
      MyBand.Left := MyRegion.Left;
      MyBand.MoveBehind; // Looks better when you "view it"
      MyBand.Top := MyRegion.Top;
      MyBand.Width := MyRegion.Width;  // 5a - Place Text components in "HeaderBand" just created
      MyText := MyBand.CreateChild(TRaveText, 'TextName') As TRaveText;
      MyText.Left := MyBand.Left + 0.2;
      MyText.Top := 0.01; // Band.Top ???
      MyText.Font.Size := 10;
      MyText.Font.Style := MyText.Font.Style + [fsBold];
      MyText.FontJustify := pjLeft;
      MyText.Text := 'Surname, First';
      MyText.Width := 2; // DataText.Name.dtName.width ???
      // 5b
      MyText := MyBand.CreateChild(TRaveText, 'TextStreet') As TRaveText;
      MyText.Left := MyBand.Left + 2.1; // prior text + 0.1 ???
      MyText.Top := 0.01; // Band.Top ???
      MyText.Font.Size := 10;
      MyText.Font.Style := MyText.Font.Style + [fsBold];
      MyText.FontJustify := pjCenter;
      MyText.Text := 'Street';
      MyText.Width := 2; // DataText.Name.dtName.width ???
      // 5c
      MyText := MyBand.CreateChild(TRaveText, 'TextStreet') As TRaveText;
      MyText.Left := MyBand.Left + 4.1; // prior text + 0.1 ???
      MyText.Top := 0.01;
      MyText.Font.Size := 10;
      MyText.Font.Style := MyText.Font.Style + [fsBold];
      MyText.FontJustify := pjCenter;
      MyText.Text := 'City State Zip';
      MyText.Width := 2; // DataText.Name.dtName.width ???
      // 5d - draw a horizontal line
      MyLine := MyBand.CreateChild(TRaveHLine, 'BottomLine') As TRaveHLine;
      MyLine.Left := 0; // MyBand.Left;
      MyLine.LineWidth := 2;
      //MyLine.LineWidthType := wtPoints;
      MyLine.Top := MyBand.Height - 0.01;
      MyLine.Width := MyRegion.Width;  // 6 - Create Report Title Band controlled by "DetailBand" ========
      MyTitleBand := MyRegion.CreateChild(TRaveBand, 'TitleBand') As TRaveBand;
      MyTitleBand.ControllerBand := MyDataBand;
      MyTitleBand.MoveBehind; // Looks better when you "view it"
      MyTitleBand.MoveBehind;
      MyTitleBand.BandStyle.PrintLoc := MyTitleBand.BandStyle.PrintLoc + [plBodyHeader];
      MyTitleBand.Left := MyRegion.Left;
      MyTitleBand.Width := MyRegion.Width;
      MyTitleBand.Height := 0.35;
      // 6a - Create Text component for "Report Title"
      MyText := MyTitleBand.CreateChild(TRaveText, 'TitleText') As TRaveText;
      MyText.Left := MyTitleBand.Left;
      MyText.Top := 0.01;
      MyText.Font.Size := 20;
      MyText.FontJustify := pjCenter;
      MyText.Text := 'Sample Members Report';
      MyText.Width := MyTitleBand.Width;  // 7 - OK, run it =================================================
      RvProject1.ExecuteReport('Report1');
      // ONLY use this so you can view report design
      // RvProject1.ProjectFile := 'ProjectTest.rav';
      // RvProject1.Save; 
      RvProject1.Close;
    End;End.
      

  2.   

    把这些贴子放在一个Form里试了一下。编绎通过,执行错误。
    什么时候再看看