How to set FastReport3 query parameter in code

Posted on 2006-04-24
Last Modified: 2008-01-09
I have been testing FastReports3 and have everything working.  I have an ADOQuery adding INSIDE the report with a Parameter in the query string of :EnrollmentRID

I captured the OnBeforePrint and searched for the parameter.  I foundit and set it, but the report uses the default parameter that I added in design mode and ignores the parameter that I set.

Is there another place where I am supposed to do this?  or does anyone see something wrong with my code.

I go through all of the datasetas and check all of the parameters for each dataset against all of the possible parameters.

procedure TdmData.frxRptBeforePrint(Sender: TfrxReportComponent);
    sl          : TStringlist;
    ndx         : Integer;
    frxDS       : TFrxDataset;
    qry         : TADOQuery;
    ParamNdx    : Integer;
    ParamName   : String;

    //go through all of the queries and set the parameters -- check each query for
    //all possible parameters

    sl := TStringlist.Create;
        for ndx :=  0 to sl.count-1 do begin
            frxDS := frxRpt.GetDataset(sl[ndx]);

            qry := TADOQUery(TFrxDBDataset(frxDS).DataSet);
            for ParamNdx := 0 to qry.Parameters.Count-1 do begin
                ParamName := UPPERCASE(qry.Parameters.Items[ParamNdx].Name);

                if ParamName='PARTICIPANTRID' then
                    qry.Parameters.Items[ParamNdx].Value := fParticipantRID
                else if ParamName='ENROLLMENTRID' then
                    qry.Parameters.Items[ParamNdx].Value := fEnrollmentRID
                else if ParamName='VOUCHERRID' then
                    qry.Parameters.Items[ParamNdx].Value := fVOUCHERRID
                else if ParamName='SERVICERID' then
                    qry.Parameters.Items[ParamNdx].Value := fSERVICERID
                else if ParamName='FOLLOWUPRID' then
                    qry.Parameters.Items[ParamNdx].Value := fFOLLOWUPRID;


Question by:kfoster11
    LVL 27

    Expert Comment

    could it be, that the datasets are already open, before u set the parameters?
    LVL 7

    Accepted Solution

    I already checked that and active was set to false.

    I found the solution myself.  Here it is if anyone is interested.

    1--> Inside a FastReport3 .fr3 file you add a variable through the designer.  I added my sql parameter 'EnrollmentRID' and set it to 0.
    2--> IN the TFrxADOQuery components Params editor I set the param value to <EnrollmentRID> which ties it to the variable defined in step 1 above.
    3--> The fastreports TFrxReport component has an event 'ongetvalue' that is called once for each variable in the report prior to the report running the queries with parameters (Const VariableName:String;var Value:Variant).  So I simply checked the variable name and if it is 'EnrollmentRID' i set Value := fEnrollmentRID;
    4-->  It Worked!

    I have used Crystal Reports and Rave Reports extensively for years.  I was led to check out FastReports3 which is Delphi Based a couple of weeks ago through another question on Experts Exchange and as a Delphi Developer it is the MOST complete and flexible tool that I have seen.  Awsome!
    LVL 27

    Expert Comment

    very interesting, didn't have FastReports3, but guess i should do a look to it

    meikl ;-)
    LVL 7

    Author Comment

    thats fine

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video discusses moving either the default database or any database to a new volume.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now