macf00bar
macf00bar

Reputation: 700

Delphi 5 & Crystal XI Rel. 2 (RDC) how to?

I'm trying to work with the class from JosephStyons but I do get an "Invalid Index" Error on the line where the "User ID" should get set.

FRpt.Database.Tables[i].ConnectionProperties.Item['User ID'] := edUserName.Text;

Here's my environment:

WinXP Sp3, Crystal Reports Developer XI Rel.2 SP4, Delphi 5 Update Pack 1

Any help or ideas greatly appreciated!

Thx, Reinhard

Upvotes: 0

Views: 1030

Answers (3)

C Harmon
C Harmon

Reputation: 208

Your value for [i] could be the culprit...I can't remember for sure but I believe the first table will be Table[1] instead of Table[0] as one would expect.

I altered my loop to use:

CrTables := CrDatabase.Tables;
for crTableObj in crTables do

You might try stepping through the table using a for loop as shown above or by starting with 1 instead of 0.

I hope this helps.

Upvotes: 1

C Harmon
C Harmon

Reputation: 208

Are you also setting the password, server name and database name?

procedure TReports.LogonToDBTables(cReport:
  CrystalDecisions.CrystalReports.Engine.ReportDocument;
  ConnInfo: ConnectionInfo);
var
  CrDataBase: Database;
  CrTables: Tables;
  CrTableObj: TObject;
  CrTable: Table;
  CrTableLogonInfo: TableLogonInfo;
  iSubReportIndex: smallint;
begin
  CrDataBase := CReport.Database;
  CrTables := CrDatabase.Tables;
  cReport.DataSourceConnections[0].IntegratedSecurity := False;

  for crTableObj in crTables do
    begin
      crTable := CrystalDecisions.CrystalReports.Engine.Table(crTableObj);
      crTableLogonInfo := crTable.LogOnInfo;
      crTableLogonInfo.ConnectionInfo := ConnInfo;
      crTable.ApplyLogOnInfo(crTableLogonInfo);
    end;
end;

function TReports.GetConnectionInfo(): ConnectionInfo;
var
  cTemp: ConnectionInfo;
begin
  cTemp := ConnectionInfo.Create();
  cTemp.AllowCustomConnection := True;
  cTemp.ServerName := GetServerName();
  cTemp.DatabaseName := GetDBName();
  cTemp.UserID := GetDBUserID();
  cTemp.Password := GetDBPassword();
  Result := cTemp;
end;

Upvotes: 0

Francesca
Francesca

Reputation: 21650

Put a break point on that line and use Evaluate/Modify.
It will return an error if you try something invalid.

  1. Examine FRpt.Database.Tables[i] and see if it's valid for what you think are the min and max values for i.
    If Tables is an array, one way to avoid that is to use ...Low(Tables) to High(Tables)

  2. If you get your Table Ok, examine FRpt.Database.Tables[i].ConnectionProperties.Item['User ID'] and see if it's valid.
    It might be that the Item getter does not like the space embedded in "User ID". Some products need either to surround by special characters like "[User ID]", other to replace by an underscore like "User_ID"

Upvotes: 0

Related Questions