Switching Aliases
If I allow the end-user to switch to another alias, (tables are closed
aliases switched, and reopened),
all is well with the exception of Report Builder reports already created.
The existing Report Builder reports "point" back to the default alias data.
However, if the user creates a new report, the table data reflects that of
the currently selected alias.
The alias switching code resets the RB data dictionary to the new alias
name, and all RB components which
rely on an alias are switched. Obviously, this seems to work since new table
instances are showing the corresponding data.
Any ideas as to why existing RB reports are hanging on to the alias
defined at design time? I'm obviously missing something simple.
TIA,
John
aliases switched, and reopened),
all is well with the exception of Report Builder reports already created.
The existing Report Builder reports "point" back to the default alias data.
However, if the user creates a new report, the table data reflects that of
the currently selected alias.
The alias switching code resets the RB data dictionary to the new alias
name, and all RB components which
rely on an alias are switched. Obviously, this seems to work since new table
instances are showing the corresponding data.
Any ideas as to why existing RB reports are hanging on to the alias
defined at design time? I'm obviously missing something simple.
TIA,
John
This discussion has been closed.
Comments
When you save a repor template, the database name is saved down with it.
Are you seeing this behavior when using DADE or just using TDataSets? If
you are using DADE, take a look at the article below for more information on
how to update the database name in a saved template.
-------------------------------------------------
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 daSQL.pas.
The example code extracts only DataViews[0]. If the report
contains multiple dataviews, you will need to iterate thru
all of the entries in the DataViews[] array.
-------------------------------------------------
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;
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
This looks like it will do the trick.
John