在Delphi XE3中打印Crystal Reports XI表单的解决方案

时间:2013-03-11 15:20:01

标签: delphi delphi-xe crystal-reports-xi

在遇到与其他人一样的问题之后,我想出了这个解决方案来预览/打印Crystal Reports XI报告。这为登录序列借了几行。我仍然无法在* TLB.pas文件中找到任何允许我直接登录服务器而不是在表列表中向下运行的内容。无论如何,这就是我现在所拥有的。希望它可以帮助别人!

Unit CrystalReports;
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,          Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.OleCtrls, ActiveX, ComObj, Data.DB, Data.Win.ADODB,
    CrystalActiveXReportViewerLib11_TLB, Vcl.OleServer, CrystalReportsControllersLib_TLB;

    type
    TCrystalReportForm = class(TForm)
        CRV: TCrystalActiveXReportViewer;
        procedure DisplayReport;
    private
        { Private declarations }
    public
        {Public declarations }
        ReportName : WideString;
        ReportCaption : String;
        ReportSelectionFormula : WideString;
    end;

    var
    CRXIRuntime : Variant;

    implementation

    {$R *.dfm}

    procedure TCrystalReportForm.DisplayReport;
    var
    CrystalReport : variant;
    i : integer;

    begin
    CrystalReport := CRXIRuntime.OpenReport(ReportName);
    for i := 1 to CrystalReport.Database.Tables.Count do begin
        CrystalReport.Database.Tables[1].ConnectionProperties.Item['User ID'] := 'user';
        CrystalReport.Database.Tables[1].ConnectionProperties.Item['Password'] := 'password';
    end;
    CrystalReport.FormulaSyntax := 0;
    Caption := ReportCaption;
    CrystalReport.RecordSelectionFormula := ReportSelectionFormula;
    CRV.Align := alClient;
    CRV.ReportSource := CrystalReport;
    WindowState := wsMaximized;
    CRV.ViewReport;
    ShowModal;
    end;

    begin
    CRXIRuntime := CreateOleObject('CrystalRuntime.Application');
    end.

0 个答案:

没有答案