dataview not working properly
Hi. i am using Delphi 6, RB 7.03 and Firebird 1.5
i have RAP reports stored in one database as blobs, but i need to copy them
to another database (same DB Structure, different data...). I have used a
couple of different methods to do this, but generally when i do it the
dataviews seem to lose their settings somehow. ie when i copy them to the
2nd database and try to run them from there the Firebird login prompt comes
up (which is set to false on the TIBDatabase component in my project) and
then the report doesn't show up properly after you enter the login details.
To fix the problem after coping the reports i have to manually go through
each report and delete the dataview and re-add it. This is a hassle. Is
this a known problem with a remedy? oh yeah - the ways that i was copying
the reports from one DB to the other - 1. i opened the report in design
mode through report explorer and did a File - Save to File and then
connected to the other DB and made a new report in report explorer and did a
File - Load from File and then saved it back to the 2nd DB. 2. i made a
little program that simply copies the DB record from one DB to the other.
and my problem happens with both methods...
I hope thats not too confusing?!?!??
Cheers
Adam.
i have RAP reports stored in one database as blobs, but i need to copy them
to another database (same DB Structure, different data...). I have used a
couple of different methods to do this, but generally when i do it the
dataviews seem to lose their settings somehow. ie when i copy them to the
2nd database and try to run them from there the Firebird login prompt comes
up (which is set to false on the TIBDatabase component in my project) and
then the report doesn't show up properly after you enter the login details.
To fix the problem after coping the reports i have to manually go through
each report and delete the dataview and re-add it. This is a hassle. Is
this a known problem with a remedy? oh yeah - the ways that i was copying
the reports from one DB to the other - 1. i opened the report in design
mode through report explorer and did a File - Save to File and then
connected to the other DB and made a new report in report explorer and did a
File - Load from File and then saved it back to the 2nd DB. 2. i made a
little program that simply copies the DB record from one DB to the other.
and my problem happens with both methods...
I hope thats not too confusing?!?!??
Cheers
Adam.
This discussion has been closed.
Comments
-------------------------------------------------
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;
--
Tech Support mailto:support@digital-metaphors.com
Digital Metaphors http://www.digital-metaphors.com
--
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
i tried that code, it runs through the code fine, but when i click the
preview tab or data tab of the report designer i get an access violation,
which i can't find where it is. any thoughts?
Adam.
Modify your Delphi library path from RBuider\Lib to RBuilder\Source and set
the debugger options to break on Delphi language exceptions. Then run the
same test.
--
Nard Moseley
Digital Metaphors Corporation
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
it seems when it gets to the GetMagicSQLText in daSQL.pas the access
violation occurs because the FEditSQLAsText (boolean property) has no value.
I think that somewhere between the GetSQLObject and SetSQLObject you had me
do to specify the databasename when the report template is loaded, the daSQL
object is being destroyed and not created again properly. but i don't know
the RB code well enough to work out what is happening. i had to change the
aReport parameter in GetSQLObject and SetSQLObject from TppReport to
TppCustomReport when i implemented these procedures, could this have
anything to do with it?
Sorry if this topic has swayed from RAP to DADE
Cheers
Adam.
I created an example that you can download...
www.digital-metaphors.com/tips/DadeUpdateDatabaseName.zip
--
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
for some reason, after i assigned the database name, the
report.ShowAutoSearchDialog was being set to false, so after re-assigning
database name i just set it to true again and everything works great.
Cheers
Adam.