1 (edited by joshuA 2022-05-21 13:52:11)

Topic: [SOLVED] User Input On A Report

Hi folks,

I was wondering if it would be possible to send a field (in this case a memo) containing a one-time use per report- like for a custom header for instance.

I'm not sure how to send the field over to the report since it's not part of a table in the database.

Any help or ideas would be appreciated.
-joshuA

Post's attachments

Attachment icon 519-customize-reports-1.zip 343.37 kb, 190 downloads since 2022-05-19 

"Energy and persistence conquer all things."

2 (edited by sparrow 2022-05-19 20:38:44)

Re: [SOLVED] User Input On A Report

Hi JoshuA,


You can transfer almost everything to the report.
It is better to do it from a script.
You can create the same SQL query and add a set of variables to it where
there will be any of your fields with text for use in the report.
Here is an example of variables: http://myvisualdatabase.com/forum/viewtopic.php?id=4110
You can also search the forum for examples.

Post's attachments

Attachment icon customize-rep-ex.zip 352.29 kb, 210 downloads since 2022-05-19 

Re: [SOLVED] User Input On A Report

Hi Josh, Hi Sparrow,
You can also do it using the standard 'report' action rather than 'report(SQL)'
Derek.

Post's attachments

Attachment icon customize-reports2.zip 356 kb, 242 downloads since 2022-05-20 

Re: [SOLVED] User Input On A Report

hi sparrow, hi derek,


Thank you both as always!  And I learned from both of your examples...


sparrow:
Thanks for the link and the example.  I usually do search the forums first, but I wasn't sure what to search for in this case.  For some reason "report variables" didn't come to mind. hmm  My apologies for that tho.


derek:
Nice, I always like your approach of doing things from MVD.  I have been trying to design my projects this way too.

In my working project, I have too many things controlling the tablegrid output, and I couldn't get the simple Report to work correctly.  I'm going see if I can figure out why that is, so I may have further questions about that big_smile


another question:
When declaring that report variable, what are all of those single quotes doing?

frmMain.frxReport.Variables['FromMemo'] := ''''+s+'''';

Why are they necessary, aside from breaking the script lol

-joshuA

"Energy and persistence conquer all things."

Re: [SOLVED] User Input On A Report

So there are four ' single quote characters.
The two outer quotes are obvious- they enclose the two other quote characters.
Theses inner two are ones in question.  Is the first inner one like an escape character for the second inner one?
Thanks

"Energy and persistence conquer all things."

Re: [SOLVED] User Input On A Report

Well- for anyone else interested in the answer to my last question, I was able to find a detailed explanation for it.

And it is, as I was expecting- a form of escaping characters.  But I wanted to share what I found...


While this is noted in the FastReport PDF manual on page 87, it doesn't go into any details about why... which is what I was curious about.

The online manual has a page about modifying variable values.  And I'll paste the content below:


It should be noted, that when accessing a report variable its value is calculated if it is of string type. That means the variable whose value is 'Table1.“Field1”' will return a value of a DB field and not the 'Table1."Field1"' string. You should be careful when assigning a string-type value to a report variable. For example, this code will raise the exception “unknown variable 'test'” when running a report:

frxReport1.Variables['My Variable'] := 'test';

because FastReport is trying to calculate a value for variable 'test'. The right way to pass a string value is:

frxReport1.Variables['My Variable'] := '''' + 'test' + '''';

In this case the variable value, string 'test', will be shown without errors. But keep in mind that:

  • a string should not contain single quotes : all single quotes must be doubled;

  • a string should not contain #13 or #10 symbols.

In some cases it is easier to pass variables using a script.


-joshuA

"Energy and persistence conquer all things."