[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to set FastReport3 query parameter in code

Posted on 2006-04-24
6
Medium Priority
?
1,601 Views
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);
var
    sl          : TStringlist;
    ndx         : Integer;
    frxDS       : TFrxDataset;
    qry         : TADOQuery;
    ParamNdx    : Integer;
    ParamName   : String;

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

    sl := TStringlist.Create;
    try
        frxRpt.GetDataSetList(sl);
        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;
            end;
        end;

    finally
        sl.Free;
    end;
end;

0
Comment
Question by:kfoster11
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 16533072
could it be, that the datasets are already open, before u set the parameters?
0
 
LVL 7

Accepted Solution

by:
kfoster11 earned 0 total points
ID: 16535471
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!
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 16536179
very interesting, didn't have FastReports3, but guess i should do a look to it

meikl ;-)
0
 
LVL 7

Author Comment

by:kfoster11
ID: 16536916
thats fine
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

834 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