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

Change Database name?

edited February 2002 in General
I have a report with queries inside it. How do I change a database name
from a querie (data will be moved for other database)?

Thanks

--
David Gurevitz
gure@centroin.com.br
gure@clinicadelphi.com.br

Job:
Av. Presidente Vargas 529, 20º Andar, Centro
Rio de Janeiro, RJ ZIP:20071-003 Brazil - Phone(21)507-3740/507-3778
Company Home Page: http://www.clinicadelphi.com.br

Home:
Av. Afranio de Melo Franco 85/404, Leblon
Rio de Janeiro, R.J ZIP:22430-060 Brazil - Phone(21)540-9204
Personal Home Page: http://www.geocities.com/CapeCanaveral/6340

Comments

  • edited February 2002
    -------------------------------------------------
    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
    a FieldAlias 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
    lSQL.DatabaseName := Designer.DataSettings.DatabaseName;

    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 := 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 := TdaQueryDataView(lDataView).SQL;

    end;

    Result := (aSQL <> nil);

    end;


    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com
This discussion has been closed.