2

私の (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 ライブラリを使用してレポートを表示していますが、これは面倒で難しく、愚かで避けられません (この投稿を参照してください)。
  • レポートは Crystal XI、SP4 にあります
  • 議論のために、レポートはすべて Oracle 10g データベースに対するものであると仮定しましょう。
  • 私の開発マシンは Windows Vista を使用しており、ほとんどのユーザーは XP を使用しています。

誰かが提供できる助けに感謝します。

4

1 に答える 1

3

Tables[i].ConnectionProperties で DSN 項目を探します。非ODBCにはありません.ODBCには常にあるはずです.AFAIK.

于 2008-12-23T15:37:42.297 に答える