delphi - 在登录之前,如何在运行时确定 Crystal XI 报表的连接方法?

标签 delphi crystal-reports activex delphi-2007

在我的 (Win32) 应用程序中,我正在显示 Crystal Reports。

我在运行时设置了登录信息。然而,Crystal 决定根据报表的连接方式,使用几个不同的名称来引用数据库名称。例如,如果报表通过 ODBC 连接进行连接,则称为“数据源”,但如果直接连接,则称为“服务器”。

当然,直到运行时我们才知道将调用哪个报告。

目前,我通过吞下异常并尝试替代方法来解决该问题,如下所示:

procedure TCrystalReporter11.SetLoginInfo(const username, password,
  server : string);
var
  i : integer;
begin
  //set user name and password
  //crystal only accepts these values if they are CONST params
  for i := 1 to FRpt.Database.Tables.Count do begin
    FRpt.Database.Tables[i].ConnectionProperties.Item['User ID'] := username;
    FRpt.Database.Tables[i].ConnectionProperties.Item['Password'] := password;
    try
      {
      Some reports use direct connections, and others use an ODBC Data Source.
      Crystal XI uses a different label to refer to the database name in each
      method.
      I don't know how to determine in advance which method is being used, so:
          First, we try the direct connection.
          If that fails, we try the "data source" method.

      Reference: "Crystal Reports XI Technical Reference", pages 41 thru 46;
                 "Common ConnectionProperties"
      }
      FRpt.Database.Tables[i].ConnectionProperties.Item['Server'] := server;
    except on E: Exception do
      FRpt.Database.Tables[i].ConnectionProperties.Item['Data Source'] := server;
    end;
  end;
end;

理想情况下,我想说的是:

case  FRpt.Database.Tables[i].ConnectionProperties.ConnectMethod of
  crymethod_ODBC : sIdx := 'Data Source';
  crymethod_Direct : sIdx := 'Server';
  ...other methods...
end;  //case
FRpt.Database.Tables[i].ConnectionProperties.Item[sIdx] := server;

所以我的问题是:

在登录之前,如何在运行时确定 Crystal XI 报表的连接方法?

背景信息:

  • 我使用的是 Delphi 2007
  • 我正在显示 使用 ActiveX 的报告 图书馆,很麻烦 困难、愚蠢、不可避免 (see this post)。
  • 报告采用 Crystal XI SP4
  • 为了讨论方便,我们假设报告都是针对 Oracle 10g 数据库
  • 我的开发计算机使用的是 Windows Vista,大多数用户使用的是 XP。

非常感谢您提供的任何帮助。

最佳答案

在 Tables[i].ConnectionProperties 中查找 DSN 项。非 ODBC 不会有它,据我所知,ODBC 总是应该有。

关于delphi - 在登录之前,如何在运行时确定 Crystal XI 报表的连接方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/389113/

相关文章:

javascript - 没有 SSL 的 ASP.NET 表单的数据加密

c# - 如何使用 JavaScript 从外部调用 C# 应用程序?

c# - 是否可以在 C# 中编写将在 Excel 中运行的 ActiveX 控件?

windows - 为什么中断 0x2A 在 x64 中不起作用?

regex - 如何从正则表达式子模式中排除一个单词?

crystal-reports - 导出为 PDF 时,t 更改为 "ti"

c# - 我正在使用 mysql 存储过程。我的 SP 返回数据集,如何将值绑定(bind)到 Crystal 报表中

delphi - 如何允许表单接受文件删除而不处理 Windows 消息?

delphi - 从内存流读取多个位图

c# - ASP.NET - Crystal Report Viewer 打印按钮在 ASP.NET 中不起作用