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

"ppdesigner.datasettings.databasename" saved to the template file?

edited February 2003 in General
"TppDesigner.DataSettings" allows you to configure the settings to be used
by the query editor of the Designer.
So if I design a RTM template file using my own
"TppDesigner.DataSettings.DataBaseName", the file will be saved with the SQL
query accessing to this Databasename.

What about if my end-users try to open/print a template made by me?
Obviously, they have no acces to my "DataSettings.DataBaseName" path,
so...can they print templates made by other people?

I have been looking for a property like "Template.SQL.DataBaseName", so I
can assign it when a template is loaded in my program.
Is it possible?

Comments

  • edited February 2003

    Open any of our demos in RBuilder\Demos\EndUser Databases\

    Notice that we always use a connection component (i.e. TDatabase,
    TADOConnection, etc).

    See the article below and notice the part about:

    "We recommend that the DatabaseName
    refer to a TDatabase connection component or to
    an Alias to provide flexibility for changing
    the connection parameters."





    -------------------------------------------------
    Tech Tip: How to modify the DatabaseName stored
    with a DADE Query
    -------------------------------------------------

    Currently when DADE is used to create dataviews,
    the DatabaseName is stored as part of the query
    definition. (This is consistent with Delphi's
    approach to specifying a database connection for
    a Query object).

    In some cases, you may decide that the
    DatabaseName needs to be modified at a later date.

    We recommend that the DatabaseName
    refer to a TDatabase connection component or to
    an Alias to provide flexibility for changing
    the connection parameters.

    A second way to handle this issue is to implement
    some code that specifies a DatabaseName
    whenever a template is loaded. This can be accomplished
    by using the Report.Template.OnLoadEnd event.


    1. Declare an event-handler procedure in the private
    section of your form declaration.

    type
    myForm = class(TForm)
    private
    procedure ReportTemplateLoadEndEvent(Sender: TObject);
    public
    end;


    2. Use the FormCreate event to assign the event-handler to
    the event property.

    procedure myForm.FormCreate(Sender: TObject)
    begin
    Report1.Template.OnLoadEnd := ReportTemplateLoadEndEvent;

    end;

    3. Add code to the event-handler to specify the database name.


    procedure myForm.ReportTemplateLoadEndEvent(Sender: TObject)
    var
    lSQL: TdaSQL;

    begin
    if GetSQLObject(Report1, lSQL) then
    begin
    lSQL.DatabaseName := Designer.DataSettings.DatabaseName;
    SetSQLObject(Report, lSQL);
    lSQL.Free;

    end;

    end;


    4. Below is a tech tip for extracting the SQL object
    from a report. TdaSQL is a class defined in daQClass.pas.

    -------------------------------------------------
    Tech Tip: How to access the SQL object associated
    with a Report created using DADE
    -------------------------------------------------

    uses
    daDatMod;


    function GetSQLObject(aReport: TppReport; var aSQL: TdaSQL): Boolean;
    var
    lDataModule: TdaDataModule;
    lDataView: TdaDataView;
    begin

    aSQL := TdaSQL.Create(nil);

    {get the datamodule}
    lDataModule := daGetDataModule(aReport);

    if (lDataModule <> nil) then
    begin
    lDataView := lDataModule.DataViews[0];

    if (lDataView <> nil) and (lDataView is TdaQueryDataView) then
    aSQL.Assign(TdaQueryDataView(lDataView).SQL);

    end;

    Result := (aSQL <> nil);

    end;


    procedure SetSQLObject(aReport: TppReport; aSQL: TdaSQL);
    var
    lDataModule: TdaDataModule;
    lDataView: TdaDataView;
    begin


    {get the datamodule}
    lDataModule := daGetDataModule(aReport);

    if (lDataModule <> nil) then
    begin
    lDataView := lDataModule.DataViews[0];

    if (lDataView <> nil) and (lDataView is TdaQueryDataView) then
    TdaQueryDataView(lDataView).SQL := aSQL;

    end;

    end;





    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com

    --
    Nard Moseley
    Digital Metaphors
    http://www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited February 2003
    Thanks, but I get an Access Volation trying to load templates with SQL code.
    If I load other templates (without sql code) aI can load them without
    problem.

    Why?


  • edited February 2003
    Sorry.
    I have changed some code and now it works.
    Thanks for the tip!

    "Santy Concepci?n" escribi? en el mensaje
This discussion has been closed.