Delphi 2007 中的水晶报表

发布于 2024-08-07 16:40:40 字数 1396 浏览 8 评论 0原文

我有:

Delphi 2007

Crystal 11

Delphi 7 版本的 Crystal VCL 组件(我知道的最新版本,它在 D2007 中编译得很好)

一个非常简单的测试 Crystal 报告,用 Crystal 11 编写,它只是将表格转储到屏幕上(没有选择标准,没有公式,只是直接数据)

我尝试过

创建了一个新的 VCL 表单应用程序

将 TCrpe 组件放在表单上将

“ReportName”属性设置为我的测试报告。

我在表单上放置了一个按钮,并在其后面放置了一行:

Crpe1.Execute

如果报表的“使用报表保存数据”选项已打开,则此操作正常。

如果我关闭该选项,那么我需要提供登录凭据。

使用此代码(一百万年前在 Delphi 5 中运行良好):

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  logonItem: integer;
begin
  Crpe1.LogOnServer.Clear;
  logonItem := Crpe1.LogOnServer.Add('MYSERVER.MYDOMAIN.COM');
  Crpe1.LogonServer[logonItem].UserID := 'USERNAME';
  Crpe1.LogOnServer[logonItem].Password := 'PASSWORD';
  Crpe1.LogOnServer[logonItem].DatabaseName := 'MYDATABASE';
  Crpe1.Execute;
end;

我收到此错误:

---------------------------
Project2
---------------------------
Error:536 Error in File C:\REPORT.RPT:

Unable to connect: incorrect log on parameters.

Execute <PEStartPrintJob>.
---------------------------
OK   
---------------------------

我做错了什么?如何向 Delphi 中的 Crystal VCL 组件提供登录凭据?我当前的解决方法是相当难看,而且我有很多遗留代码需要转换。如果我能以简单的方式使用 VCL 组件,那就太好了。

I have:

Delphi 2007

Crystal 11

The Delphi 7 version of the Crystal VCL component (latest one I'm aware of, and it compiles fine in D2007)

A very simple test Crystal report, written in Crystal 11, which just dumps a table onto the screen (no selection criteria, no formulas, just straight data)

I tried

Created a new VCL forms app

Dropped the TCrpe component on the form

Set the "ReportName" property to my test report.

I dropped a button on the form, and behind it placed one line:

Crpe1.Execute

If the report has the "Save Data With Report" option turned on, then this works fine.

If I turn that option off, then I need to provide login credentials.

Using this code (which worked fine in Delphi 5 a million years ago):

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  logonItem: integer;
begin
  Crpe1.LogOnServer.Clear;
  logonItem := Crpe1.LogOnServer.Add('MYSERVER.MYDOMAIN.COM');
  Crpe1.LogonServer[logonItem].UserID := 'USERNAME';
  Crpe1.LogOnServer[logonItem].Password := 'PASSWORD';
  Crpe1.LogOnServer[logonItem].DatabaseName := 'MYDATABASE';
  Crpe1.Execute;
end;

I get this error:

---------------------------
Project2
---------------------------
Error:536 Error in File C:\REPORT.RPT:

Unable to connect: incorrect log on parameters.

Execute <PEStartPrintJob>.
---------------------------
OK   
---------------------------

What am I doing wrong? How can I provide login credentials to the Crystal VCL component in Delphi? My current workaround is pretty ugly, and I have a lot of legacy code to convert. It would be really nice if I could use the VCL component in a straightforward way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

俏︾媚 2024-08-14 16:40:40

我在Delphi 6中使用VCL,效果很好。但我不使用 LogOnServer 属性,而是使用 LogOnInfo。

这适用于任何报告以及包含子报告的报告(因为这些报告也需要提供凭据):

 With CRPE1 Do
 Begin
      With SubReports Do
      Begin
           Retrieve;
           If (Count > 0) then
           For i := 0 To (Count - 1) Do
           Begin
                ItemIndex := i;

                LogOnInfo.Retrieve;
                For j := 0 to LogOnInfo.Count - 1 Do
                Begin
                     LogOnInfo[j];

                     With LogOnInfo Do
                     Begin
                          ServerName := MyDataSource;
                          DatabaseName := DatabasePath;
                          UserID := DBUser;
                          Password := sPwd;
                     End;
                End; {For j}

                Tables.Retrieve;
           End; {For i}

           ItemIndex := 0;
      End; {With SubReports}

      SubReports[0];
 End; {With CRPE1}

I use the VCL in Delphi 6, works great. But I don't use the LogOnServer property, I use the LogOnInfo.

This works for any report, and reports that contain subreports (as these need the credentials supplying as well):

 With CRPE1 Do
 Begin
      With SubReports Do
      Begin
           Retrieve;
           If (Count > 0) then
           For i := 0 To (Count - 1) Do
           Begin
                ItemIndex := i;

                LogOnInfo.Retrieve;
                For j := 0 to LogOnInfo.Count - 1 Do
                Begin
                     LogOnInfo[j];

                     With LogOnInfo Do
                     Begin
                          ServerName := MyDataSource;
                          DatabaseName := DatabasePath;
                          UserID := DBUser;
                          Password := sPwd;
                     End;
                End; {For j}

                Tables.Retrieve;
           End; {For i}

           ItemIndex := 0;
      End; {With SubReports}

      SubReports[0];
 End; {With CRPE1}
遇见了你 2024-08-14 16:40:40

以下是一些使用 VCL 组件的旧“遗留”代码:

mCrpe.reportname:=mfilename;
mCrpe.Connect.UserID := CustomReportCurrentUser;

mCrpe.connect.ServerName:='servername';
mCrpe.connect.DataBaseName:='databasename';
mCrpe.connect.propagate:=True;
mCrpe.Connect.Password := CustomReportClientPass;



try
  mConnected := mCrpe.Connect.Test;
except
  on e: eDBEngineError do begin
    showmessage(e.message);
  end;
end;

mCrpe.windowbuttonbar.refreshbtn:=true;
mCrpe.discardsaveddata;
mCrpe.Show;

不久前,我读到 Crystal VCL 组件正在“废弃”。从那时起,我已迁移到 Active X RDC 组件。不过,它需要在您的目标计算机上安装 Active X。

Here is some old "legacy" code which uses the VCL component:

mCrpe.reportname:=mfilename;
mCrpe.Connect.UserID := CustomReportCurrentUser;

mCrpe.connect.ServerName:='servername';
mCrpe.connect.DataBaseName:='databasename';
mCrpe.connect.propagate:=True;
mCrpe.Connect.Password := CustomReportClientPass;



try
  mConnected := mCrpe.Connect.Test;
except
  on e: eDBEngineError do begin
    showmessage(e.message);
  end;
end;

mCrpe.windowbuttonbar.refreshbtn:=true;
mCrpe.discardsaveddata;
mCrpe.Show;

Some time ago I had read the Crystal VCL component was being "sunsetted". Since then I have migrated to the Active X RDC component. It will require the Active X to be installed on your target computers though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文