Home End User
New Blog Posts: Merging Reports - Part 1 and Part 2

Extract SQL from .rtm file

edited June 2004 in End User
Hi All,

How can I see the sql for a report loaded from an .rtm file?

I have the .rtm file loaded into a TppReport. What is the property that
stores the SQL for the report?

Thanks,
Stacey

Comments

  • edited June 2004
    Thought I'd mention...I'm using RB v6.01 and D5.

    Here is as far as I could pick up in the NG :

    procedure TForm1.btnShowSQLClick(Sender: TObject);
    var
    TempReport : TppCustomReport;
    iSQL : TdaSQL;

    begin
    if FileExists(edtReportPath.FileName) then begin
    TempReport := TppCustomReport.Create(self);

    try
    with TempReport do begin
    Template.Filename := edtReportPath.FileName;
    Template.LoadFromFile;
    ShowSQLText(TempReport, '');
    end;
    finally
    FreeAndNil(TempReport);
    end;
    end;
    end;

    I get an 'Abstract Error' on Template.LoadFromFile. If I change
    TppCustomReport, to a TppReport, it makes it past the loadfromfile, but then
    I get an error in sql, cannot find 'alias CRDatabase'.

    What am I missing?

    Thanks In Advance,
    Stacey
  • edited June 2004
    Hi Stacey,

    Check out the following example on how to extract the SQL from a report.
    Take a look at the GetSQLObject method for how this should be done. If you
    are loading templates, you will need to use the template event
    Template.OnLoadEnd to retrieve the SQL object as it will not exist until
    that event is fired. See the article below for more information on using
    template events.

    http://www.digital-metaphors.com/tips/ExtractSQLObject.zip

    ----------------------------------------------
    Tech Tip: Using Template Events
    ----------------------------------------------

    The Report.Template object has several events that can be used for
    customizing what happens when a report is loaded or saved:

    - OnLoadStart
    - OnLoadEnd
    - OnNew
    - OnSaveStart
    - OnSaveEnd


    The OnLoadEnd and OnNew events are often used to perform actions related
    to report and data initialization.

    The OnSaveEnd event is often used to save additional descriptive
    ("meta") data to the database each time the report is saved.

    Example:

    The Report.Template events are public and therefore must be assigned at
    run-time.


    1. In the private section of your form declaration you can declare an
    event-handler method:

    TForm = class(TForm)
    private
    procedure myTemplateOnLoadEndEvent(Sender: TObject);

    public

    end;


    2. In the Form.OnCreate event, you can assign the event-handler to the
    event:

    procedure TForm1.FormCreate(Sender: TObject);
    begin

    ppReport1.Template.OnLoadEnd := myTemplateOnLoadEndEvent;

    end;


    3. Implement the event-handler method:

    procedure TForm1.myTemplateOnLoadEndEvent(Sender: TObject);
    begin

    {add code here to initial the report or data, etc. }
    ppReport1.PrinterSetup.MarginTop := 0.5;

    end;


    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.