Page 1 of 1

CRYSTAL REPORT need help (Passing parameter)

Posted: Wed Apr 12, 2017 3:35 am
by dutch
Dear All,

I need to use CRYSTAL REPORT XI but I cannot run the sample program from Fernando González Diez's sample. I occur an error as picture.

I use xHB, FWH1612, BCC7 and CR XI.
Imageimage hosting

Code: Select all

// Our first Window in FiveWin !!!

#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oActiveX, oCRApp, oRpt

   oCRApp := CreateObject("CrystalRuntime.Application.11") 
   oRpt   := oCRApp:OpenReport("C:\Users\dutch\Desktop\CR11\testcr11.rpt")
   
   DEFINE WINDOW oWnd FROM 3, 6 TO 20, 70 ;
      TITLE "Welcome to " + FWDESCRIPTION COLOR "W/B"

   oActiveX := TActiveX():New( oWnd, "CrystalReports11.ActivexReportViewer.1" )  
   oWnd:oClient := oActiveX
   oActiveX:SetProp( "ReportSource", oRpt )
   oActiveX:SetProp( "EnableStopButton",     1  )
   oActiveX:SetProp( "EnableAnimationCtrl",  0  )
   oActiveX:SetProp( "EnableCloseButton",    1  ) 
   oActiveX:SetProp( "EnableExportButton",   1  )
   oActiveX:SetProp( "EnablePopupMenu",      0  )  // revisar, es interesante pero da error
   oActiveX:SetProp( "EnableRefreshButton",  0  )
   oActiveX:bOnEvent = { | event, aParams | EventInfo( event, aParams, oRpt, oActivex  ) } 
   
   oActiveX:Do( "Viewreport" )
   
   ACTIVATE WINDOW oWnd ;
      VALID MsgYesNo( "Are you sure?", "Do you want to exit?" )

return nil
 
function EventInfo( event, aParams, oRpt, oActivex )
   local cMsg := cValToChar( event ) //+ CRLF
return cMsg
Thanks for any help or idea.

Re: CRYSTAL REPORT need help

Posted: Wed Apr 12, 2017 8:52 am
by AHF
Dutch,

Just as a guide line.

Code: Select all

  oCrystal := CreateObject("CrystalRuntime.Application.11" )
  oReport  := oCrystal:OpenReport( cReport)
  if(!empty(oReport:ReportTitle),oReport:ReportTitle,strtran(cfilenopath(alltrim(creport)),".RPT"))
  oReport:DiscardSavedData()
  oReport:SetDialogParentWindow(nHwnd)  //our window app?

  oSection := oReport:Sections:item("PHb") //REPORT HEADER B
  oSection:AddPictureObject((cLocal)+"\logo.jpg",0,0)

  //databse and tables location
  oDbName   := oReport:Database
  oDbTables := oDbname:Tables
  nTables :=  oDbTables:count()

  //reassigning new tables and datasource
  for n := 1 to nTables
      oDbTable := oDbTables:Item(n)
      oDbTable:dllname := "crdb_ads.dll"
      oProp := oDBTable:ConnectionProperties()
      oProp:DeleteAll()

      if rddrddsetdefault() ="ADS"
     oProp:add("DatabaseName","DSN=ADS_CDX;Datadirectory="+
                         ((cLocal)+"\mydatadictionary.add")+;
                        ";ConnectionHandle=alltrim(str(nHandle))"+;
                        ";Compression=Internet;DefaultType=FoxPro;ServerTypes=7"+;
                        ";AdvantageLocking=ON;CharSet=OEM;Language=ANSI;Locking=RECORD"+;
            ";UID=crystalreports;PWD=mypass"+;
            ";EncryptionPassword=mypass")

      else
          oDbTable:location := (cLocal)+"\"+oDbtable:name+".dbf"

      endif

  next

  oFormulas:= oReport:FormulaFields
  nFormulas := oFormulas:count()
    for n := 1 to nFormulas
        oFormula := oFormulas:item(n)
        //test formulas
        do case
          case upper(oFormula:name)= "{@company_name}"
               oFormula:text  :='"'+alltrim(aDtempresa[1,1])+'"'+chr(0)

        endcase

    next

    oReport:ExportOptions:Reset()
    if lLetter
       oReport:ExportOptions:DestinationType := 1
       oReport:ExportOptions:FormatType := 35
       oReport:ExportOptions:RTFExportAllPages := 1

    else
       oReport:ExportOptions:DestinationType := 1
       oReport:ExportOptions:FormatType := 31
       oReport:ExportOptions:PDFExportAllPages := 1

    endif
    

    DEFINE ICON oicon NAME "FOLLOWUP"

    DEFINE WINDOW oWnd ICON oicon TITLE cTitle

    oCRViewer := TactiveX():New(ownd,"CrystalReports.ActiveXReportViewer" )

    oCRViewer:EnableExportButton :=1
    oCRViewer:EnableStopButton:= 1
    oCRViewer:EnableNavigationControls:=1
    oCRViewer:EnablePopupMenu:=0
    oCRViewer:EnableCloseButton:=0

    if !lSql
       oCRViewer:DisplayGroupTree:=0
       oCRViewer:EnableDrillDown:=0
       oCRViewer:EnableGroupTree:=0
       oCRViewer:EnableStopButton:= 0
       oCRViewer:EnablePrintButton  := 0 //20.10.14

    endif
      
    oCRViewer:ReportSource:= oReport

    oCRViewer:ViewReport()
    oCrViewerZoom:=75

    oWnd:oClient := oCRViewer

    ownd:setmenu(MsgB(ownd,oReport,oCrViewer,creport,cuser,nport,ldocelect))

    ACTIVATE WINDOW oWnd MAXIMIZED ;
    VALID (oReport:CancelPrinting(),oCrystal:CanClose(),oReport := nil ,.t.)

Re: CRYSTAL REPORT need help

Posted: Tue Apr 18, 2017 5:15 am
by dutch
Dear Antonio,

Thank you so much, I can do it now.