Use DfAllRpt.pkg Use Crystal\CheckForCrystal.dg Use dfrptvw.pkg Use Windows.pkg Use DfLine.Pkg Use cRichEdit.pkg Use File_dlg.Pkg Use cCrystal.pkg DEFERRED_VIEW Activate_oReportInformationCR FOR ; ; Object oReportInformationCR is a ReportView // This ReportView is a sample of the use of cCrystal.pkg. This package // allows a connection to Crystal Reports by calling the RDC COM methods. // It is based on Crystal Reports XI. This sample shows how to get information from // a Crystal Report. It gets the selection formula, the sort order defintion // and all formulas of the report. Set Border_Style to Border_Thick Set Label to "Report Information" Set Location to 6 7 Set Size to 306 365 Set piMinSize to 320 365 Object oReportnameTextBox is a Textbox Set Label to "Last report read:" Set FontSize to 4 0 Set Location to 36 8 Set Size to 10 53 Set TypeFace to "MS Sans Serif" End_Object // oReportnameTextBox Object oReportNameForm is a Form Set Label to "Crystal Report:" Set Size to 13 244 Set Location to 10 56 Set peAnchors to anTopLeftRight Set Label_Col_Offset to 2 Set Label_Justification_Mode to jMode_Right Set Prompt_Button_Mode to pb_PromptOn Procedure Entering // clear information from previous report Send ClearAllData // clear report name Set value to "" // disable the run button Set enabled_state of oRunButton to False End_Procedure // Sent when the prompt key is pressed, start selection list Procedure Prompt Integer iSelected iNumPaths String sSelectedFile String sDataDir Get psDataPath of (phoWorkspace(ghoApplication)) to sDataDir Get CountOfPaths of (phoWorkspace(ghoApplication)) sDataDir to iNumPaths If (iNumPaths > 1) Get PathAtIndex of (phoWorkspace(ghoApplication)) sDataDir 1 to sDataDir Set Initial_Folder of oNewDialog to sDataDir // disable the run button Set enabled_state of oRunButton to False // Start the save as dialog Get Show_Dialog of oNewDialog to iSelected If iSelected Begin Get File_Name of oNewDialog to sSelectedFile Set Value to sSelectedFile End End_Procedure // Start_Prompt End_Object // oReportNameForm Object oReadReportButton is a Button Set Label to "Read Report" Set Size to 14 51 Set Location to 10 304 Set peAnchors to anTopRight Set Default_State to True Procedure OnClick Boolean bReportOK bCrystalOK String sReportName Get Value of oReportNameForm to sReportName // Check if the report name was specified and report actually exists Get ValidateReportName sReportName to bReportOK If (bReportOK) Begin Get CheckCrystalEnvironment of oCheckForCrystal to bCrystalOK If (bCrystalOK) Begin Send ReadReport of oCrystalReport1 sReportName End Else Begin Send DisplayDialog of oCheckForCrystal End End Else Begin Send activate of oReportNameForm End End_Procedure // OnClick End_Object // oReadReportButton Object oLineControl1 is a LineControl Set Size to 2 349 Set Location to 26 6 Set peAnchors to anLeftRight End_Object // oLineControl1 Object oSelectionEdit is a cRichEdit Set Label to "Selection" Set Size to 38 349 Set Location to 63 7 Set Color to clWhite Set TextColor to clBlack Set peAnchors to anLeftRight Set Read_Only_State to True End_Object // oSelectionEdit Object oSortOrderList is a List Set Label to "Sort Order" Set Size to 62 349 Set Location to 118 7 Set peAnchors to anTopLeftRight Set Label_Col_Offset to 0 Set Label_Row_Offset to 1 Set Label_Justification_Mode to jMode_Top End_Object // oSortOrderList Object oFormulas is a cRichEdit Set Label to "Formulas" Set Size to 61 349 Set Location to 198 6 Set Color to clWhite Set TextColor to clBlack Set peAnchors to anBottomLeftRight Set Label_Col_Offset to -1 Set Read_Only_State to True End_Object // oFormulas Object oRunButton is a Button Set Label to "Run Report" Set Location to 266 248 Set peAnchors to anBottomRight Set Enabled_State to False Procedure OnClick Send RunReport of oCrystalReport1 End_Procedure // OnClick End_Object // oRunButton Object oCancelButton is a Button Set Label to "Cancel" Set Location to 266 302 Set peAnchors to anBottomRight Procedure OnClick Send Request_Cancel End_Procedure // OnClick End_Object // oCancelButton Object oNewDialog is a OpenDialog Set Dialog_Caption to "Select Crystal Report" Set Filter_String to "Crystal Report (*.rpt)|*.rpt|All Files|*.*" Set HideReadOnly_State to True End_Object // oNewDialog Object oCrystalReport1 is a cCrystal Set psReportName to "" Procedure ProcessReportData Handle hoReport Handle hoSortFields hoSortField hoField hoFormulas hoFormula Integer iSortItem iSortCount iFormulaItem iFormulaCount Boolean bAttached String sRptTitle sSelection sCurSortField sCurFormName sCurFormContents Variant vSortField vField vFormulaField Handle hoGroups hoGroup Variant vGroups vGroup Integer iGroups iGroup Get ReportObject to hoReport // Show report title. If no title exists, just show file name Get ComReportTitle of hoReport to sRptTitle If (sRptTitle='') Get psReportName to sRptTitle Set Label of oReportNameTextBox to ("Last report read:" * sRptTitle) // Get Selection Get ComRecordSelectionFormula of hoReport to sSelection Send AppendText of oSelectionEdit sSelection // Get sort order // First show group sort fields, then regular sort fields Get Create of hoReport U_cCrystalGroupNameFieldDefinitions to hoGroups Get Create of hoReport U_cCrystalGroupNameFieldDefinition to hoGroup Get ComGroupNameFields of hoReport to vGroups Set pvComObject of hoGroups to vGroups Get IsComObjectCreated of hoGroups to bAttached If (bAttached) Begin Get ComCount of hoGroups to iGroups For iGroup From 1 to iGroups Get ComItem of hoGroups iGroup to vGroup Set pvComObject of hoGroup to vGroup Get IsComObjectCreated of hoGroup to bAttached If (bAttached) Begin Get ComName of hoGroup to sCurSortField Send Add_Item of oSortOrderList MSG_None sCurSortField End Loop End Get SortFieldsObject of hoReport to hoSortFields If (hoSortFields) Begin Get Create of hoSortFields U_cCrystalSortField to hoSortField Get Create of hoSortFields U_cCrystalFieldObject to hoField Get ComCount of hoSortFields to iSortCount For iSortItem From 1 to iSortCount Get ComItem of hoSortFields iSortItem to vSortField Set pvComObject of hoSortField to vSortField Get IsComObjectCreated of hoSortField to bAttached If (bAttached) Begin Get ComField of hoSortField to vField Set pvComObject of hoField to vField Get IsComObjectCreated of hoField to bAttached If (bAttached) Begin Get ComName of hoField to sCurSortField Send Add_Item of oSortOrderList MSG_None sCurSortField End End Loop End // Get formulas Get FormulaFieldDefinitionsObject of hoReport to hoFormulas If (hoFormulas) Begin Get Create of hoFormulas U_cCrystalFormulaFieldDefinition to hoFormula Get ComCount of hoFormulas to iFormulaCount For iFormulaItem From 1 to iFormulaCount Get ComItem of hoFormulas iFormulaItem to vFormulaField Set pvComObject of hoFormula to vFormulaField Get IsComObjectCreated of hoFormula to bAttached If (bAttached) Begin Get ComFormulaFieldName of hoFormula to sCurFormName Get ComText of hoFormula to sCurFormContents Send AppendText of oFormulas (sCurFormName + ":" + sCurFormContents +Character(10)+Character(13)) End Loop End End_Procedure // ProcessReportData Procedure ReadReport String sReportName Boolean bReportOK Boolean bOk // Clear all child object Send ClearAllData // Setup the reportname and open the report so we can query information from it Set psReportName to sReportName Get OpenReport to bOk If bOk Begin Send ProcessReportData Send CloseReport Set enabled_state of oRunButton to True End End_Procedure // ReadReport End_Object // oCrystalReport1 Procedure ClearAllData Send Delete_Data of oSelectionEdit Send Delete_Data of oSortOrderList Send Delete_Data of oFormulas End_Procedure Function ReportExists String sRPTName Returns Boolean Boolean bReportExists // Check if the report actually exists File_Exist sRPTName bReportExists Function_Return bReportExists End_Function Function ValidateReportName String sReportName Returns Boolean Boolean bReportNameOK Move False to bReportNameOK If (sReportName="") Begin Send Info_Box "Select or specify a report." "Report Information" End Else Begin Get ReportExists sReportName to bReportNameOK If (not(bReportNameOK)) Begin Send Info_Box ("The report file " + sReportName + " does not exist. Select or specify another one.") "Report Information" End End Function_Return bReportNameOK End_Function CD_End_Object // oReportInformationCR