Skip to Content
author's profile photo Former Member
Former Member

CR9 VCL raises exception editing formula

Hello Experts!

I need some assistance because something I'm doing or something in the Crystal9 VCL is causing me major pain.

I have an unpatched Crystal Reports 9 installed. Delphi 7. Crystal 9 VCL.

I've written a Delphi 7 application that generates a report based on criteria entered by the user on a screen. In order to present to the end user some information about the criteria selected for the current report, I've created the following code:

cr.ReportName := ReportName;

if cr.Formulas.IndexOf('RunComments') <> -1 then


cr.FormulaByName('RunComments').Formula.Text := '"Test"';


When I run my app, and do not include the formula setting, I have no problems.

If I try to read either the Name of the formula, or the current text I get a blow up. I've not tried to read or write other formulas.

When I attempt to set RunComments (which obviously must exist in the report, the indexOf correctly skips over the setting of the formula if the formula has not been added to the report) I get an error. IndexOf also (on inspection) returns 5.

This piece of code in UCRPE32 TCrpeFormulas.SetIndex raises the exception:

if not Cr.FCrpeEngine.PEGetHandleString(hName, pText, iName) then



case Cr.GetErrorMsg(Cr.FPrintJob,errNoOption,errEngine,'',

'Formulas.SetIndex(' + IntToStr(nIndex) + ') <PEGetHandleString - Formula Name>') of

errIgnore : Exit;

errAbort : Abort;

errRaise : raise ECrpeError.Create(Cr.FLastErrorNumber, Cr.FLastErrorString);



The error message is:

Error: 502 Invalid text or object handle. Formulas.SetIndex(5) <PEGetHandleString - Formula Name>

From reading the VCL help this code is in the examples

Crpe1.ReportName := 'C:\Company.rpt';

Crpe1.FormulaByName('Formula One').Formula.Text := '{table.NUM} * 100';


I am either missing something (like a "readFormulas" method I need to call) or there's a bug in the VCL. Either way I am stuck and I need to deliver this shortly.

Any assistance appreciated. My work around will be to write this to a temp table and read it into a sub-report, but that's really not very elegant.



Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 04:16 PM

    FYI -

    Applying CR9 SP 6 fixed this issue

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 21, 2008 at 04:04 PM

    Hi Robert,

    First thing is you should download and install all patches.

    Next is test the fornula in the Report Designer to verify it works. Once their then get the formula to see what the text looks like and the type info on the formula. If it says the type is wrong it usually means it is.

    Thank you


    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.