开发者

Crystal reports in Delphi 2007

I have:

Delphi 2007

Crystal 11

The Delphi 7 version of the Crystal VCL component (latest one I'm aware of, and it compiles fine in D2007)

A very simple test Crystal report, written in Crystal 11, which just dumps a table onto the screen (no selection criteria, no formulas, just straight data)

I tried

Created a new VCL forms app

Dropped the TCrpe component on the form

Set the "ReportName" property to my test report.

I dropped a button on the form, and behind it placed one line:

Crpe1.Execute

If the report has the "Save Data With Report" option turned on, then this works fine.

If I turn that option off, then I need to provide login credentials.

Using this code (which worked fine in Delphi 5 a million years ago):

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  logonItem: integer;
begin
  Crpe1.LogOnServer.Clear;
  logonItem := Crpe1.LogOnServer.Add('MYSERVER.MYDOMAIN.COM');
  Crpe1.LogonServer[logonItem].UserID := 'USERNAME';
  Crpe1.LogOnServer[logonItem].Password := 'PASSWORD';
  Crpe1.LogOnServer[logonItem].DatabaseName := 'MYDATABASE';
  Crpe1.Execute;
end;

I get this error:

---------------------------
Project2
---------------------------
Error:536 Error in File C:\REPORT.RPT:

Unable to connect: incorrect log on parameters.

Execute <PEStartPrintJob>.
---------------------------
OK   
---------------------------

What am I doing wrong? How can I provide login credentials to the Crystal VCL component in Delphi? My current workaround is pretty ugly, and I have a lot of legacy code to convert. It would be rea开发者_JAVA技巧lly nice if I could use the VCL component in a straightforward way.


I use the VCL in Delphi 6, works great. But I don't use the LogOnServer property, I use the LogOnInfo.

This works for any report, and reports that contain subreports (as these need the credentials supplying as well):

 With CRPE1 Do
 Begin
      With SubReports Do
      Begin
           Retrieve;
           If (Count > 0) then
           For i := 0 To (Count - 1) Do
           Begin
                ItemIndex := i;

                LogOnInfo.Retrieve;
                For j := 0 to LogOnInfo.Count - 1 Do
                Begin
                     LogOnInfo[j];

                     With LogOnInfo Do
                     Begin
                          ServerName := MyDataSource;
                          DatabaseName := DatabasePath;
                          UserID := DBUser;
                          Password := sPwd;
                     End;
                End; {For j}

                Tables.Retrieve;
           End; {For i}

           ItemIndex := 0;
      End; {With SubReports}

      SubReports[0];
 End; {With CRPE1}


Here is some old "legacy" code which uses the VCL component:

mCrpe.reportname:=mfilename;
mCrpe.Connect.UserID := CustomReportCurrentUser;

mCrpe.connect.ServerName:='servername';
mCrpe.connect.DataBaseName:='databasename';
mCrpe.connect.propagate:=True;
mCrpe.Connect.Password := CustomReportClientPass;



try
  mConnected := mCrpe.Connect.Test;
except
  on e: eDBEngineError do begin
    showmessage(e.message);
  end;
end;

mCrpe.windowbuttonbar.refreshbtn:=true;
mCrpe.discardsaveddata;
mCrpe.Show;

Some time ago I had read the Crystal VCL component was being "sunsetted". Since then I have migrated to the Active X RDC component. It will require the Active X to be installed on your target computers though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜