在我的 (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 报表的连接方式?
背景资料:
- 我正在使用德尔福 2007
- 我正在使用 ActiveX 库显示报告,这既麻烦又困难、愚蠢且不可避免(请参阅这篇文章)。
- 报告在 Crystal XI,SP4 中
- 为了便于讨论,我们假设报告都是针对 Oracle 10g 数据库的
- 我的开发机器使用的是 Windows Vista,大多数用户使用的是 XP。
非常感谢有人可以提供的任何帮助。