views:

390

answers:

4

Hi Guys!

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

A: 

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.

C Harmon
thanks for the hint - changed the loop to:for i := 1 to FRpt1.Database.Tables.Count do but now I get an access violation
pastacool
A: 

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"

François
tanks for you inputadd 1: there is only one tables object and it's index starts at 1 instead of 0 so the "invalid index" problem has gone.add2: as you can see, ['User ID'] is already a string with single quotation marks
pastacool
A: 

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;

C Harmon
thanks for your input: as for the login I think I have a working solution. the next problem I face is that if i set a parameter which is a stored procedure parameter (shown for parametername = '@P_') the AddCurrentValue function does not set the currentvalue but instead the DefaultValue. How the heck did crystal-businessobjects-sap ever get paid for such a crappy software??
pastacool
If you've got time please look at http://stackoverflow.com/questions/1073636/crystal-xi-rel2-rdc-parameter-passingthx
pastacool
Are you calling ClearCurrentValueAndRange before trying to set the parameter value?CRReport.ParameterFields.GetItemByName('ExemplarFee', '').ClearCurrentValueAndRange;CRReport.ParameterFields.GetItemByName('ExemplarFee', '').AddCurrentValue (misVars.Reports.cExemplarFeeAmount);
C Harmon
yes, since I've saved the report with CR XI I can work with AddCurrentValue but the report preview with CrystalReportsActiveXViewer does not show any data. I've also tried to read SQLQueryString from the Report Object but all I see is that all stored procedure parameters are "NULL". I will give it a few more days but if I can't figure it out until mid next week I will go insane and recommend some other reporting solution to my manager.
pastacool
A: 

Delphi & Crystal Reports XI Developer Edition Release 1 work well together. After release 2 Delphi VCL Components support were removed. =(

hello and welcome to SO! your "answer" is not an answer to the question since you are talking about the VCL component but the question was about the RDC (COM) component. you should have posted this as a comment instead
pastacool