title: How can I determine the connection method of a Crystal XI report at runtime, before logging in?
body: <p>In my (Win32) application, I am displaying Crystal Reports.</p>
  
  <p>I set the login information at runtime.  However, Crystal kindly decided to refer to the database name by several different names, depending on how the report connects.  For instance, if the report connects through an ODBC connection, then it is called "Data Source", but if it connects directly, then it is called "Server".</p>
  
  <p>Of course we don't know until runtime which report is going to be called.</p>
  
  <p>Currently, I work around the issue by swallowing an exception and trying an alternate method, like this:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>Ideally, I'd like to say something like:</p>
  
  <pre><code>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;
  </code></pre>
  
  <h1>So my question is:</h1>
  
  <p>How can I determine the connection method of a Crystal XI report at runtime, before logging in?</p>
  
  <h1>Background info:</h1>
  
  <ul>
  <li>I'm using Delphi 2007</li>
  <li>I'm displaying
  the report using the ActiveX
  library, which is cumbersome and
  difficult and stupid and unavoidable
  (<a href="https://stackoverflow.com/questions/378089/how-can-i-display-crystal-xi-reports-inside-a-delphi-2007-application">see this post</a>).</li>
  <li>Reports are in Crystal XI, SP4</li>
  <li>For the sake of discussion, let's assume reports are all against an Oracle 10g
  database</li>
  <li>My dev machine is using Windows Vista, most users are on XP.</li>
  </ul>
  
  <p>Many thanks for any help that someone can offer.</p>