Crystal Reports ActiveX查看器

slwdgvem  于 2022-10-16  发布在  其他
关注(0)|答案(3)|浏览(289)

当使用Crystal Reports ActiveX查看器(在本例中为Delphi XE3)时,如何指定要查看的报表文件?CR控件中没有可用于输入报表名称或位置的属性。

7hiiyaii

7hiiyaii1#

Crystal Reports XI ActiveX查看器无法正常工作。我猜您是想用它来让Crystal Reports与Delphi一起工作。它不起作用。它甚至在其他地方都不起作用。最新安装的Crystal Reports XI甚至没有附带ActiveX版本,只有.Net版本。
仍然有一些安装程序在周围(或在您的本地网络上)包含此ActiveX控件,但CR XI论坛讨论(Crystal Reports现在由SAP管理)指出,ActiveX控件在大约十年前就被弃用,在过去五年中不起作用,并在两年多前从最新的安装程序中完全删除。

mzaanser

mzaanser2#

ActiveXViewer*可以与Delphi XE3配合使用。以下是一个示例:

unit crystalreports;

interface

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;

type 
TReportForm = class(TForm)
 CrystalReportsViewer: TCrystalActiveXReportViewer; 
 PreviewButton: TButton; 
 procedure PreviewButtonClick(Sender: TObject); 
 private { Private declarations } 
 public { Public declarations } 
 end;

 var ReportForm : TReportForm;

 implementation

 {$R *.dfm}

 procedure TReportForm.PreviewButtonClick(Sender: TObject); 
    var CReport, CRApp : variant; 
    i :integer; 

begin 
CRApp := CreateOleObject('CrystalRuntime.Application'); 
CReport := CRApp.OpenReport('C:\Crystal Reports Test\companydatasheet.rpt',0 ); 
for i := 1 to CReport.Database.Tables.Count do 
begin 
    CReport.Database.Tables[1].ConnectionProperties.Item['User ID'] := 'sa';  
    CReport.Database.Tables[1].ConnectionProperties.Item['Password'] := 'secret'; 
end; 
CReport.RecordSelectionFormula := '{member.member_no} = "101"';        
CrystalReportsViewer.Align := alClient; 
CrystalReportsViewer.ReportSource := CReport; 
ReportForm.WindowState := wsMaximized; 
PreviewButton.Visible := False; 
CrystalReportsViewer.ViewReport; 
CrystalReportsViewer.Show; PreviewButton.Visible := True; 
end;

end.
mqxuamgl

mqxuamgl3#

我同意ActiveXViewer确实适用于Delphi 10.1。
如何在Delphi中使用水晶报表?
https://randemsystems.com/crystalreports.html获取并安装运行时版本XI-“RDC 11.5-Runtime-(11/25/10)”
要将RDC运行时库包含到Delphi中,请在Delphi中启动一个新项目,并执行以下步骤:
选择“项目”菜单,然后选择“导入类型库”。
1.在导入类型库中,选择Crystal Report x ActiveX Designer Runtime Library,将所有的Txxxxxx重命名为TCrxxxxxxxxx Sample:TApplication和Treport以及TDatabase类名为TCrApplication TCrReport和TCrDatabase,以避免命名冲突。
1.单击Install按钮,单击Into New Package选项卡,提供新程序包的文件名路径,然后选择OK。
1.在确认框中,在Delphi的ActiveX选项卡上单击是。现在有一个应用程序对象图标和TCrReport对象图标。
1.从Delphi的ActiveX选项卡中,将一个应用程序对象放到Form1上。这会将OleServer和CRAXDRT_TLB添加到Form1上的USES子句。阅读更多关于..。https://developerpublish.com/crystal-report-in-delphi-7/
这是一个加载水晶报表文件并使用界面或OleObject查看它的示例应用程序

unit UFormCrystalReports;
{$WARN SYMBOL_PLATFORM OFF}
{$WARN UNIT_PLATFORM OFF}

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
  ActiveX, ComObj, Data.DB, Data.Win.ADODB, Vcl.Buttons, Vcl.ExtCtrls,
  Vcl.OleCtrls, Vcl.OleServer, CrystalActiveXReportViewerLib11_5_TLB, CRAXDRT_TLB;

type
  TFormCrystalReports = class(TForm)
    Panel1: TPanel;
    PreviewButton: TButton;
    CrystalReportsViewer: TCrystalActiveXReportViewer;
    PreviewInterface: TButton;
    OpenFileButton: TButton;
    procedure PreviewButtonClick(Sender: TObject);
    procedure PreviewInterfaceClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure OpenFileButtonClick(Sender: TObject);
  private
    { Private declarations }
    _Continue: integer;
    fFileName: string;
    pDllName, pProvider, pServerName, pDatabaseName, pUserID, pPassword: string;
    aRep: IReport;
    procedure ConnectToDatabase;
  public
    { Public declarations }
  end;

var
  FormCrystalReports: TFormCrystalReports;

implementation

{$R *.dfm}

procedure TFormCrystalReports.FormCreate(Sender: TObject);
begin
  fFileName := 'L1_900.rpt';
  Caption := 'Crystal report viewer XI : read file = ' + fFileName;
  UseLatestCommonDialogs := True;
end;

procedure TFormCrystalReports.OpenFileButtonClick(Sender: TObject);
var
  cExportTitle, cExportFilter, cExportExt, cFilename, cDirectory: string;
begin

  cExportFilter := 'Crystal report files |*.rpt';
  cExportExt := 'rpt';
  cExportTitle := 'Select the report file';
  cFilename := 'L1_900.rpt';
  cDirectory := GetCurrentDir();

  if (PromptForFileName(cFilename, cExportFilter, cExportExt, cExportTitle, cDirectory, False)) then
    begin
      if (MessageBox(0, PChar('The selected report file is' + #13#10 +
        PChar(ExtractFileName(cFilename))), PChar('Confirmation'), MB_ICONQUESTION or MB_YESNO or
        MB_TOPMOST or MB_SYSTEMMODAL or MB_DEFBUTTON1) = idYes) then
          if FileExists( cFileName ) then
           begin
             fFileName := cFilename;
              Caption := 'Crystal report viewer XI : read file = ' + fFileName;
              ShowMessage('Run report -> "Preview with Interface" ' + #13#10 +' or "Preview with OleObject" button');
           end
          else
            with TTaskDialog.Create(Self) do
              begin
                try
                  Caption := 'The report file is not exists.';
                  CommonButtons := [tcbOk];
                  DefaultButton := tcbOk;
                  ExpandButtonCaption := 'Additional information';
                  ExpandedText := 'Looking for file : ' + #13#10 + cFilename;
                  Flags := [tfAllowDialogCancellation, tfShowMarqueeProgressBar, tfPositionRelativeToWindow];
                  Title := ExtractFileName(cFilename);
                  Text := 'Sample text';
                  MainIcon := tdiWarning;
                  Execute;
                finally
                  Free;
                end;
              end;
    end;

end;

procedure TFormCrystalReports.PreviewInterfaceClick(Sender: TObject);
var
  Cr_App: TCrApplication;
begin
  Cr_App := TCrApplication.Create(Self);
  try
    pDllName := 'crdb_ado.dll';
    pProvider := 'SQLNCLI10.1';
    pServerName := 'your-servername';
    pDatabaseName := '';
    pUserID := 'your-username';
    pPassword := 'your-password';

    _Continue := 0;

    aRep := nil;
    aRep := Cr_App.OpenReport(fFileName, 1);

    ConnectToDatabase;

    if _Continue = 1 then
      begin
        // if (CrystalReportsViewer.ReportSource <> nil) then
        // IReport(CrystalReportsViewer.ReportSource).PrinterSetup(0);
        CrystalReportsViewer.Align := alClient;
        CrystalReportsViewer.ReportSource := aRep;
        CrystalReportsViewer.Visible := True;
        CrystalReportsViewer.Zoom(100);
        CrystalReportsViewer.ViewReport;

      end;

  finally
    Cr_App.free;
    Screen.Cursor := crDefault;
  end;

end;

procedure TFormCrystalReports.ConnectToDatabase;
var
  i: integer;
  DB: IDatabaseTable;
  s: string;
begin
  try
    for i := 1 to aRep.Database.Tables.Count do
      begin
        DB := aRep.Database.Tables.Item[i];
        try
          s := DB.Location;
          DB.SetLogOnInfo(pServerName, pDatabaseName, pUserID, pPassword);
          DB.Location := s;
        finally
          DB := nil;
        end;
      end;

    if aRep.Get_HasSavedData then
      aRep.DiscardSavedData;

    _Continue := 1;
  except
    _Continue := 0;
  end;

end;

procedure TFormCrystalReports.PreviewButtonClick(Sender: TObject);
var
  CReport, CRApp: variant;
  i: integer;
begin
  CRApp := CreateOleObject('CrystalRuntime.Application');
  CReport := CRApp.OpenReport(fFileName, 0);
  for i := 1 to CReport.Database.Tables.Count do
    begin
      CReport.Database.Tables[1].ConnectionProperties.Item['User ID'] := 'your-username';
      CReport.Database.Tables[1].ConnectionProperties.Item['Password'] := 'your-password';
    end;
  // CReport.RecordSelectionFormula := '{member.member_no} = "101"';
  CrystalReportsViewer.Align := alClient;
  CrystalReportsViewer.ReportSource := CReport;
  PreviewButton.Visible := False;
  CrystalReportsViewer.ViewReport;
  CrystalReportsViewer.Show;
  PreviewButton.Visible := True;
end;

end.

相关问题