0

After suffering through the same problems as others did, I came up with this solution to previewing/printing Crystal Reports XI reports. This borrows a few lines for the login sequence. I still can't find anything in the *TLB.pas files that allows me to login to the server directly rather than running down through the list of tables. Anyway, here's what I have at this point. Hope it helps someone !

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.
TLama
  • 75,147
  • 17
  • 214
  • 392
bcorll
  • 33
  • 5

0 Answers0