daSQL problem
Hi guys,
I've managed to create autosearch fields and then modified
daSQL.MagicSQL.Text on the fly on ReportOnGetAutoSearchValues event in RAP
code. I just created some pass-trough function which does that. Despite of
new daSQL.MagicSQL.Text RB generates Report using "old" daSQL.MagicSQL.Text.
What should I do to make RAP see "new"daSQL.MagicSQL.Text ?
Cheers,
Dmitry
I've managed to create autosearch fields and then modified
daSQL.MagicSQL.Text on the fly on ReportOnGetAutoSearchValues event in RAP
code. I just created some pass-trough function which does that. Despite of
new daSQL.MagicSQL.Text RB generates Report using "old" daSQL.MagicSQL.Text.
What should I do to make RAP see "new"daSQL.MagicSQL.Text ?
Cheers,
Dmitry
This discussion has been closed.
Comments
Cheers,
Dmitry
Designer. If I save report and go back to Report Explorer and then View
report from Report Explorer it works fine.
Try setting TdaSQL.SQLText rather than the MagicSQLText.
Setting SQLText should automatically set TdaSQL.EditSQLAsText to True. And
if EditSQLAsText is true, the MagicSQLText property will return the SQLText
that you assigned.
--
Nard Moseley
Digital Metaphors Corporation
http://www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Thanks for your reply. I found quite interesting thing.
Say, I have manually edited SQL like:
Select * from MyTable
Where InvoiceDate between :SDate and :EDate
When I load MagicSQL text for the first time it is exactly as above.
Then on ReportOnGetAutoSearchValues event I replace :SDate and :EDate with
my parameters, get Report displayed in Preview.
Then, without leaving Preview form, I click on "Magnifying glass icon" to
bring up my custom autosearch dialog again and then I need to do same
thing(replace "parameters" with actual values).
Obviously, ":SDate" and ":EDate" gone - they were replaced before with
actual values and
MagicSQL text now is
Select * from MyTable
Where InvoiceDate between '01/01/2000' and '01/01/2004'
So, I can not substitute parameters now. Therefore, if I open Data
Workspace(without closing report designer first !) and check SQL it still
has :SDate and :EDate ! That's exactly what I want ! How can I
programmatically get this ? TdaSQL.SQLText and MagicSQLText seem to return
modified SQL with parameters replaced.
Cheers,
Dmitry
When the ReportDesigner's Preview tab is selected and the report contains
RAP code, ReportBuilder internally saves the report definition to a temp
stream. When you leave Preview, ReportBuilder internally restores the report
definition from the temp stream. This is necessary because your RAP code can
change the report - just as you are doing.
I think you perhaps need a global RAP variable to save the initial SQL
text..
if gSQLString = '' then
gSQLString := mySQL.SQLText;
{use gSQLString to replace parameters]
{use gSQLString to set new SQLText]
--
Nard Moseley
Digital Metaphors
http://www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
I always have empty gSQLString ...
Try to simple test:
1.Create Global variable gSQLString
2. onReportBeforeAutoSearchDialogCreate(or on ReportOnGetAutoSearchValues)
put code like:
ShowMessage('My Global variable:'+gSQLString );
if gSQLString = '' then gSQLString := 'Whatever';
It happens because Report object got destroyed(Report onDestroy event fired)
even if I stay in report preview form.
Well, I need to work out some other way to keep original SQL now.
Cheers,
Dmitry
And it's always empty string. So global variable got emptied somewhere.
Okay, looks like when the new AutoSearch value is entered from the preview
panel, then the GlobalDestroy is called followed by the GlobalCreate.
You could perhaps use the Report.Parameters[] to define the string. Not sure
if that would work any better. You would probably have to add the parameter
at Delphi design-time or in the Delphi Report.Template.OnLoadEnd event. Then
in RAP code use it to save the SQL string.
--
Nard Moseley
Digital Metaphors
http://www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com