Highlighted
Absent Member.
Absent Member.
4699 views

[archive] Crystal Reports Viewer (and/or Printing) Basic Example

[Migrated content. Thread originally posted on 25 August 2008]

Does anyone have a really basic Crystal Reports viewer example that I can look at? I'm using Crystal version 11.5, the crviewer.dll, and I'm using AcuCOBOL 7.2. I've tried several different attempts at getting various bits of code from the forums to work for me, but I always seem to end up with "usage handle of Application" giving me an "Invalid HANDLE type" error when I compile. I'm pretty sure I'm just missing something to do with the ActiveX, and a complete code example would go a long way to help me figuring out what I'm doing wrong. All we're really trying to accomplish is to be able to display a Crystal Report on the screen, or send it to the printer. We do have a parameter or two that we'd eventually like to pass, but I'd settle for at least getting it to compile successfully and display the report at all! 🙂

Thanks,
Paul
0 Likes
13 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Crystal Reports Viewer (and/or Printing) Basic Example

If you could provide the offending line of code, and an extract from the definition file in which the problematic method is defined, we might be able to work something out.
I also assume you have based your coding on some examples in vb or something, would be nice to see how it is defined done there as well.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Crystal Reports Viewer (and/or Printing) Basic Example

I keep getting pulled off of this Crystal Reports Project, but I keep trying to get back to it - and I'm back to it right now, and I'm determined to get it working. I'm having trouble figuring out how to pass the report name to the CrystalActiveXReportViewer (I believe that's the right name to be working with, based on what I found in crviewer.dll).

I figure that if I can get the report to show, I'll hopefully have more luck figuring out how to pass a parameter and how to tell the report to display or just to directly print. But, one step at a time.

I have posted a zip file with a sample report, along with an Acubench project (with everything consolidated into one CBL file), and I hope someone can give me a hand with this.

Here's the link:
http://www.dmfatlanta.com/files/Project1.zip
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Crystal Reports Viewer (and/or Printing) Basic Example

The ReportSource property is supposed to be assigned a COM interface handle, not a filename.

You ought to ask Crystal Reports what object to use to load the file, then I presume this will be the handle to assign to the ReportSource property.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Crystal Reports Viewer (and/or Printing) Basic Example

Thanks for your quick response. I figured it must be something to do with Objects, and I think I'm really not grasping objects and how cobol and activex interact with them. When I got started in all this, I was working off of this previous forum thread:
http://www.acucorp.com/support/supported/customer_forum/showthread.php?t=83

I found this documentation on how to add a Crystal Viewer to a VB project:
http://devlibrary.businessobjects.com/businessobjectsxi/en/en/RDC_SDK/rdc_com_dg_doc/doc/rdcsdk_com_doc/Report_Viewers_Programming4.html

But I'm not seeing where I go from here. I feel that if I can just get a working report, I can figure out how to modify it (pass parameters, tell it to print vs. display, etc), but I just cant get it off of the ground.

Is this something that I should just be getting the Services dept to write a sample for me?

Thanks again for your help.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Crystal Reports Viewer (and/or Printing) Basic Example

There is no reason for you to look further on that link about how to add Crystal Viewer to a VB project, the other link you refer to however, is right on target.

Here is what you have to do:

The ReportSource property of the CRViewer object is expecting an object, not a filename.
What you should do is add these lines before yours:

CREATE Application OF Report HANDLE IN hReport.
MODIFY hReport OpenReport("c:\test.rpt") GIVING hReport.
Modify hReport @ReadRecords()

Then change this line of yours:

MODIFY CR-VIEWER @ReportSource = WS-FILE.

To:

MODIFY CR-VIEWER @ReportSource = hReport.
MODIFY CR-VIEWER @ViewReport().

hReport is defined as:

77 hReport USAGE HANDLE OF Report.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Crystal Reports Viewer (and/or Printing) Basic Example

Ok, I think/hope I've made some real progress. I've got the program compiling with no errors, but when I try to display the report on the screen, all I'm getting is a blank white window instead of the Crystal Viewer (despite the fact that when I was previewing the viewer in AcuBench, it was showing the correct Crystal Viewer window, with controls at the top, etc). I'm guessing that somehow the viewer just isn't getting displayed correctly, and so it's just putting a filler in its place. Here are the mods I've made to the code...

In Working Storage:
77 hReport
USAGE IS HANDLE OF CrystalActiveXReportViewer.


In the Screen Section:
01 Screen1.
03 Screen1-CrystalRep, CrystalActiveXReportViewer,
COL 2.10, LINE 2.00, LINES 70 CELLS, SIZE 80 CELLS,
ID IS 1, INITIAL-STATE (ActiveX-Res, "Res-Tag-1").


And then in the main program, I've tried putting this section of code before opening the window, and before and after opening the screen:
CREATE CrystalActiveXReportViewer HANDLE IN hReport.
MODIFY hReport, @ReportSource("c:\testreport.rpt").
MODIFY hReport, @EnableToolbar(1).
MODIFY hReport, @DisplayToolbar(1).
MODIFY hReport, @DisplayGroupTree(1).
MODIFY hReport, @EnableGroupTree(1).
MODIFY hReport, @ViewReport().


Complete source code (I converted strictly to a CBL and got away from AcuBench to try to clarify some issues) is available at:
http://www.dmfatlanta.com/files/Program1.zip

Any thoughts or help is greatly appreciated.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Crystal Reports Viewer (and/or Printing) Basic Example

All my documents state that the ReportSource property of CrystalActiveXReportViewer is supposed to be set to a handle of a Report object, not a file name.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Crystal Reports Viewer (and/or Printing) Basic Example

I ended up setting the reportsource directly to a file name because it seemed that that's what was being done in this doc:
http://msdn.microsoft.com/en-us/library/ms225508.aspx

I'm not getting a type mismatch, so I figured I couldn't be too far off the mark, but maybe I still am.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Crystal Reports Viewer (and/or Printing) Basic Example

That link is to the .net version, which is a different beast all together.

Can you post the .def file you have created?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Crystal Reports Viewer (and/or Printing) Basic Example

Thank you for all your help on this. I'm attaching my current CBL and the .DEF file for the Crystal ActiveX viewer, and I figured it may help if I explain how I've gotten this far.

You suggested:
77 hReport USAGE HANDLE OF Report.

But I get errors because "Report" is unknown. If I change this to "CrystalActiveXReportViewer" it compiles successfully.


You suggested:
CREATE Application OF Report HANDLE IN hReport.

But whenever I try to use "Application", I get errors - I removed "Application" and still get error on "Report" (which I assume is related to the first issue I mentioned above). I swapped "Report" with "CrystalActiveXReportViewer" and it compiles. My replacement line of code is:
CREATE CrystalActiveXReportViewer HANDLE IN hReport.


You suggested:
MODIFY hReport OpenReport("c:\test.rpt") GIVING hReport.

But I get errors on "OpenReport" - it doesn't know what that is. I changed it with "@ReportSource" and it compiles.


You suggested:
Modify hReport @ReadRecords()

Which doesnt' seem to be in the current version of the .def file that I'm using, I was assuming that it now automatically reads the records, so I commented this line out (again, this may be part of the problem).


You suggested:
Changing this line:
MODIFY CR-VIEWER @ReportSource = WS-FILE.

To this:
MODIFY CR-VIEWER @ReportSource = hReport.
MODIFY CR-VIEWER @ViewReport().


I think this may have just been a copy/paste error, because nowhere can I find any references to "CR-VIEWER" in my code, but it was mentioned on one of the other examples, where it was the referencing the screen section. I have tried putting several things here in place of "CR-VIEWER", including my screen section name ("CrystalReportScreen", which compiles successfully, but then gives me a memory access violation error when the program tries to execute that line of code), and "hReport" (which compiles and runs just fine, but doesn't display the report, just a blank white screen).

Thanks again,
PK
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Crystal Reports Viewer (and/or Printing) Basic Example

Hi.

I looked at the definition file, and it states:

      * ReportSource
      * Get the report source
               PROPERTY-PUT, 250, @ReportSource,
                   "IUnknown* (Property_Value)", TYPE 13


I understand why you got confused about CR-VIEWER, CR-VIEWER is a data item of type USAGE HANDLE OF CrystalActiveXReportViewer.

Now, for the Report object and its class Application.

Crystal Reports, for reasons unknown to me released their stuff in two parts back in those days when I did some stuff with this, for all I know, it is like this still:

Reports are loaded and manipulated with a Report object. This happens to be a COM object and it happens to be entirely separate from the CrystalActiveXReportViewer.

The CrystalActiveXReportViewer is an Activex, and what it does, is to receive a handle to a report object and do a visual presentation of this.


So, what you have to do, is to get to make a .def file for whatever it is that make the report object these days, it used to be something like craxdrt.dll or something.

Once you have that .def file, you add it to your existing report, create the report object, have the report object load the file and finally you can assign the report to the ReportSource property of your instance of CrystalActiveXReportViewer.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.