大家好, 刚接触水晶报表,想用它在VC++ 下开发数据库报表, 我是跟据水晶报表中英文开发帮助(CrystalDevHelp.chm)以及www.vckbase.com 在线杂志第23 其中“水晶报表在VC++ 下的简单开发”
两个都没成功,编释无错, 就是不能运行出现错误提示,现在想请教大侠,提供简单例程和开发指南以供学习。Email:[email protected]
谢谢!

解决方案 »

  1.   

    CrystalReport水晶报表中文手册 详细信息 < 电子图书 >  水晶报表中文参考手册CHM格式。[涉及平台] 平台无关
    [作者] CrystalDecisions
    [文件大小] 3804K 
    [更新日期] 2003-10-25 16:38:00 
    [下载次数] 9770  http://www.vckbase.com/tools/ebook/crw_help.rar
      

  2.   

    水晶报表是一个报表设计开发的强大工具,功能强大,设计灵活,在水晶报表光盘中只提供了一个完全动态生成报表的例子,使用繁琐。现介绍其在VC++6.0中的简单使用方法。编译环境:VC++6.0 sp5 、Windows 2000 Server sp3 (en)。一、导入水晶报表使用的动态联接库:根据实际修改文件路径。#import "C:\Documents and Settings\Administrator\桌面\cr\craxdrt9.dll" no_namespace二、定义接口指针变量//水晶报表变量IApplicationPtr m_Application;IReportPtr m_Report;//水晶报表控件变量,在对话框中加入该控件CCrystalReportViewer9 m_CRViewer1;三、具体实现步骤//实例化m_Applicationm_Application.CreateInstance (__uuidof(Application));//获取m_Report变量//staff.rpt为通过向导建立的报表文件,数据库采用SQL Server 7.0m_Report =m_Application->OpenReport ("C:\\Documents and Settings\\Administrator\\桌面\\cr\\debug\\staff.rpt");//设置报表标题m_Report->put_ReportTitle (_bstr_t("Title"));//设置数据库连接变量//数据库服务器(local),数据库名staff,用户名sa,密码sam_Report->Database ->Tables ->Item [1]->SetLogOnInfo("(local)","staff","sa","sa");//设置检索SQL命令m_Report->put_SQLQueryString ((_bstr_t)"select * from person where id<'4' order by id");//不显示重复字段m_Report->PutEnableSelectDistinctRecords (TRUE);//设置检索条件,采用水晶报表语法,功能同设置检索SQL命令m_Report->PutRecordSelectionFormula ((_bstr_t)"{person.id}='1'");//设置报表作者m_Report->PutReportAuthor ("xiaojin");//将m_Report与报表控件连接m_CRViewer1.SetReportSource(m_Report);//显示报表工具条m_CRViewer1.SetDisplayToolbar (TRUE);//不显示报表左边的分组树m_CRViewer1.SetDisplayGroupTree (FALSE);//不显示控件边框m_CRViewer1.SetDisplayBorder (FALSE);//刷新数据m_CRViewer1.Refresh ();//显示报表内容m_CRViewer1.ViewReport();
    这样,漂亮的水晶报表就显示出来了。程序异常处理部分省略,请自行加入。
      

  3.   

    CrystalReport水晶报表测试代码集锦 详细信息 < 报表与打印 >  本代码涵盖了CrystalReport8.5和CrystalReport.Net,包含VB,VC的测试代码。[代码性质] VC完整应用程序代码
    [代码作者] 王建伟
    [文件大小] 2382K 
    [更新日期] 2003-10-22 20:02:00 
    [下载次数] 3845 
     
    http://www.vckbase.com/code/winview/print/CrystalReports_samples.rar
      

  4.   

    我用的是Crystal Reports 9 VC++6.0 以上所说的,我都去试过了,就是不行,都不是Crystal Reports 9控件的。
    请问哪位大侠有Crystal Reports 9 && VC++6.0 开发的实例。真的很想搞出来。
      

  5.   

    //以下看不明,用VC60直接生成基于对话框程序
    //然后在对话框中插入ActiveX:Crystal Report Viewer Control 9
    //我只知道这些不要凡我了
    const CLSID CLSID_Application = {0xb4741fd0,0x45a6,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};
    const IID IID_IApplication = {0x0bac5cf2,0x44c9,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};
    const CLSID CLSID_ReportObjects = {0xb4741e60,0x45a6,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};
    const IID IID_IReportObjects = {0x0bac59b2,0x44c9,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};
    struct InitOle {
    InitOle()  { ::CoInitialize(NULL); }
    ~InitOle() { ::CoUninitialize();   }
    } _init_InitOle_;///////////以上是全局///////////////////////////
    BOOL CMyRDCDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here
    // A dummy variant
    VariantInit (&dummy);
    /*VARIANT*/dummy.vt = VT_EMPTY;
    HRESULT            hr = S_OK;
    // IApplicationPtr 
    /*IApplicationPtr*/m_Application=NULL; //=new IApplicationPtr;// NULL;
    m_Application.CreateInstance (__uuidof(Application));
    /*IReportPtr*/ 
    m_Report = NULL;

    // Specify the path to the report you want to print
    _bstr_t ReportPath("Report1.rpt");
    _variant_t vtEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
    // Instantiate the IApplication object
    // hr = CoCreateInstance(CLSID_Application, NULL, CLSCTX_INPROC_SERVER , IID_IApplication, (void **) &m_Application);

    //Open the Report using the OpenReport method
    m_Report = m_Application->OpenReport(ReportPath, dummy);

    //Print the Report to window
    //m_Viewer是ActiveX控件
    /*CCrystalReportViewer9*/m_Viewer.SetReportSource(m_Report);
    m_Viewer.ViewReport();

    return TRUE;  // return TRUE  unless you set the focus to a control
    }
      

  6.   

    我以前也见过这个情况,反正要注意把Crystal Report Viewer Control 9这个控件添加工程,另外要注意在程序初始时要运行:AfxOleInit和AfxEnableControlContainer;否则就会出错,有一次我没运行AfxEnableControlContainer;结果程序调试了半天
      

  7.   


    以下是错误担示:
    Unhandled exception in CrystalPro.exe (kernel32.dll): 0xe06d7363:Mirosoft C++ Execption.编释无错误,就是执行时出现提示,无法通过。
    请帮忙,谢谢。
      

  8.   


       多谢大家的回复,也是是我太CAI了,还不能从各大侠的指点中吸收精华,还是没有解决以上问题。
    以下是我的开发过程的做法,请各位指点:
    第一个例子:按照Crystal report't help 中 working with VC++ 做了第一个例子,完全按照了他的做法,可也是出现:Unhandled exception in CrystalPro.exe (kernel32.dll): 0xe06d7363:Mirosoft C++ Execption.
    以下是具体步骤,同时我添加了:导入水晶报表使用的动态联接库,#import "C:\Documents and Settings\Administrator\桌面\cr\craxdrt9.dll" no_namespace
    路径正确。1. Open Visual C++ 6.0 if it isn't already running. 
    2. On the File menu, select New. 
    3. In the New dialog box, select the MFC AppWizard (exe) from the Projects tab. 
    4. Type MyRDC for the Project Name and click OK. 
    5. In the first step of the wizard, select Dialog based and click Finish to accept the defaults for the MFC AppWizard, and then click OK in the New Project Information dialog box. 
    When the wizard executes, a dialog box appears in design mode.
    6.  Right-click the dialog box and select Insert ActiveX Control from the popup dialog box. From the list of available controls, select Crystal Report Viewer Control. 
    7. Resize the control to the desired size. 
    8. Rearrange the OK and Cancel buttons to their desired location. 
    9. Select the View|Class Wizard. 
    10. Click the Member Variables tab and ensure that the class name is CMyRDCDlg. 
    11. Add a variable for the IDC_CRVIEWER1 and click OK when prompted to add the control to the project. 
    12. Name the member variable for the viewer m_Viewer. 
    13. Click OK to save the changes and then close the dialog box. 
    14. Add a reference to the RDC runtime object Model. 
    15. On the File|Open menu, select the MyRDCdlg.h file that was generated by the MFC App wizard and click Open. 
    16. On the File|Open menu, open the MyRDC.CPP file and add the following code before the message map: 
    struct InitOle {
    InitOle()  { ::CoInitialize(NULL); }
    ~InitOle() { ::CoUninitialize();   }
    } _init_InitOle_;
    17. Declare protected member variables for the RDC's Application and Report objects in the implementation section of the MyRDCdlg.h header file. 
    For optional Variant parameters declare a protected dummy variable in the same section.
    IApplicationPtr m_Application;
    IReportPtr m_Report;
    VARIANT dummy;
    18. Add the following constants after the #endif statement in the declarations section of the MyRDCdlg.CPP file. 
    // The constants needed to create the Application and Report Objects COM objects
    const CLSID CLSID_Application = {0xb4741fd0,0x45a6,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};
    const IID IID_IApplication = {0x0bac5cf2,0x44c9,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};
    const CLSID CLSID_ReportObjects = {0xb4741e60,0x45a6,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};
    const IID IID_IReportObjects = {0x0bac59b2,0x44c9,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};
    19. Also in the MyRDCdlg.CPP file, add the following code to the CMyRDCDlg::OnInitDialog() method just before the return statement: 
    // A dummy variant
    VariantInit (&dummy);
    dummy.vt = VT_EMPTY;
    HRESULT            hr = S_OK;
    IApplicationPtr m_Application = NULL;
    IReportPtr m_Report = NULL;
                
    // Specify the path to the report you want to print
    _bstr_t ReportPath("c:\\Program Files\\Crystal Decisions\\Crystal Reports 9\\Samples\\En\\Reports\\General Business\\Inventory.rpt");
    _variant_t vtEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);// Instantiate the IApplication object
    hr = CoCreateInstance(CLSID_Application, NULL, CLSCTX_INPROC_SERVER , IID_IApplication, (void **) &m_Application);//Open the Report using the OpenReport method
    m_Report = m_Application->OpenReport(ReportPath, dummy);//Print the Report to window
    m_Viewer.SetReportSource(m_Report);
    m_Viewer.ViewReport();
    20. Finally, on the Build menu, select Rebuild All, then Execute. 
    When the app runs, it opens the report and displays it in the viewer control on the application's dialog. Click OK or Cancel to dismiss the dialog and terminate the application.
    第二个例子:  我按照oyljerry(☆勇敢的心☆) 的回复,做了第二个例子,可还是出现同样的提示,两个做法都是编释通过可都不能执行。请问这些问题出现在哪里呢,我安装的是 window2000 professinoal +sp3; Crystal report 9.0 ,Visual studio 6.0 + sp5 谢谢。
      

  9.   

    楼主小弟也在研究水晶报表这方面的问题,并且也在发贴问人.有时间大家交流一下,我的QQ是:7796816我相关的贴子是:
    http://community.csdn.net/Expert/topic/3440/3440276.xml?temp=.244198网上的例子大多调不通,我早就试过了,不过也有一些收获,有兴趣,大家分享一下.只有菜鸟才知道菜鸟会犯的错误.
      

  10.   

    楼主,我终于找到为什么网上这些例子调不通的原因了.
    吐血!!!
    原因是报表文件兼容性问题.你试着用4.5版的设计器编写报表,然后再用高版的组件载入.
    步骤:
    1.在窗口上画个高版本的报表视控件(我用的是10代)
    2.通过它在主对话框类里建一个m_crv控件对象变量(用ctrl+W)
    3.再通过ctrl+w将两个接口类IReport和IAppliation导入到你的工程中.
    具体做法:
    (1).Ctrl+w 
    (2)Add a class from type library 
    (3)选择craxdrt.tlb文件(不知道它在哪里,就用文件搜索找吧,反正装水晶报表就有
    (4)在出现的列表里按着Ctrl键选IReport和IAppliation
    (5)将在主对话框类里手动声名这两个接口类的对象变量m_IReport,m_IAppliation
    (6)将以下代码粘到主对话框类的头文件中
    #include "craxdrt.h"const CLSID CLSID_Application = {0xb4741fd0,0x45a6,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}}; const IID IID_IApplication = {0x0bac5cf2,0x44c9,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}}; const CLSID CLSID_ReportObjects = {0xb4741e60,0x45a6,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}};const IID IID_IReportObjects = {0x0bac59b2,0x44c9,0x11d1,{0xab,0xec,0x00,0xa0,0xc9,0x27,0x4b,0x91}}; class CPlkDlg : public CDialog//这句只告诉你位置,不用粘(7)OK,一切顺利,现在可以用例子代码中的片断了.如下:
    VARIANT dummy;

    VariantInit (&dummy); 

    dummy.vt = VT_EMPTY;

    // TODO: Add extra validation here
    m_Application.CreateDispatch(CLSID_Application);
    m_IReport=m_Application.OpenReport("c:/3.rpt",dummy);//注意这一句,一定要用4.5生成的报表,我用10版的生成的报表会出现错误,我也不知道为什么.
    m_crv.SetReportSource(m_IReport);
    m_crv.ViewReport();
    以上代码我是在OnOK函数里面写的.
    但我是用的10代的报表设计器,和10代码运行时库组件,真郁闷啊.!
    我真希望你比我先找到问题的所在,并告诉我,还好现在解决,头大.
    如还有疑问请在QQ上和我联系:7796816,白天工作时间都在.
      

  11.   

    我有,我做过,没有任何问题。留下一个email,我给你发个例子
      

  12.   

    blacksheep:
         谢谢你的回复,我的E-Mail:[email protected],
      

  13.   

    问题出在craxdrt.dll的版本上.
    你不能用低版本的来处理高版本的数据文件.
      

  14.   

    llm06(blacksheep):
         我也要一个,谢谢,[email protected]
      

  15.   

    你可以设置断点单步调试,看看是哪句语句导致出错的。
    水晶报表的兼容性是很有问题的,就是报表文件和控件之间的。比如.net下的水晶报表文件就不能用于其它版本的。
    而且我这边的导出都有问题,就是导出到excel之类的。
    后来我换用了vs.net自带的水晶报表控件,都没问题。但是这个控件在vs.net2003中也只能用C#或VB.net来开发,不支持vc++.net :(
    不过当时我就这样集成了一下。主程序基于win32系统,而报表程序基于.net平台,两者之间通过简单的命令行参数实现调用。网上的例子一般都还行的,我自己当时用也遇到过你说的情况。有些就是控件的注册问题,你看看IID_IReportObjects等IID值是否和你机器上的一致。