Embedding expressions in text

edited August 2010 in FastReport 4.0
I am using FR 4.3, Delphi 7. In my app there are various letters that are printed, and the user wants to be able to change the text of those letters rather than having it hard-coded. The text is stored in a table called Letters, in the field LetterText, and contains some embedded field names. This is a typical entry:

<!--fonto:Courier New--><span style="font-family:Courier New"><!--/fonto-->Thank you for your order for shoes for <B>[frxDBInvoice."Patient"]</B>. This order will be shipped on approximately <B>[frxDBInvoice."ExpectedShipDate"]</B>. The price will be approximately <B>[frxDBInvoice."Balance" #n%2.2m]</B>.
<!--fontc--></span><!--/fontc-->

In my report I included this field, [frxDBInvoice."LetterText"], in one of the bands and expected it to substitute the field values within the text when it runs so it would look like this:

Thank you for your order for shoes for John Smith. This order will be shipped on approximately 08/11/2010. The price will be approximately $250.00.

Instead, it is printing the text exactly as it is in the database, with the field names instead of the values (it does interpret the HTML code <B> correctly as bold). I have AllowExpressions set to true, and ExpressionDelimiters set to the default [,] so I don't know why it doesn't work. Is there some issue with interpreting expressions within a field pulled from a database?

Glenn

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 3:07PM
    [frxDBInvoice."LetterText"] the key is in the underlying data type of this field and what it creates when used in a memoview.
    it creates one long string when it is processed.Ie it is the expression being processed
    try this in the obp event of the band put the value of the datafield in the memos text
    then when the memo is processed the internal expression will be evaluated.
    memo1.memo.text := <frxDBinvoice."LetterText">;
    BTW you are way out of date current version is 4.9.106, you should periodically check your customer dl page and see what updates are available to you.
  • edited 3:07PM
    Thanks, that does work. But I don't really understand why doing it in code like this produces a different result.
  • gordkgordk St.Catherines On. Canada.
    edited 3:07PM
    when the memo contains [frxDBInvoice."LetterText"]
    this expression is processed and the text of that field is substituted for the expression.
    thats it done on to the next object to be processed.
    when you retreive the text of the field in the obpevent of the band and insert it into the memo,
    the memo then contains all the text with it's embedded expression before the engine handles the memo view, now when it handles the memoview the embedded expression is handled.
    the engine processess bands from top down according to type and objects in the band from left to right in order of creation.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.