Delphi FastReport Nested Expression in MemoView - delphi

I am using FastRepors v4.11 which comes with Delphi XE2
Is there a way I can set the text for a MemoView dynamically using nested expressions
I tried a couple of different ways but none seem to work
[ReportHeader."Ch[ReportHeader."Channel"]Label"]
[ReportHeader."Ch<ReportHeader."Channel">Label"]
<ReportHeader."Ch[ReportHeader."Channel"]Label">
[ReportHeader."Ch" + [ReportHeader."Channel"] + "Label"]
Channel holds a value like 1 or 2 or 3 or 4. I want the MemoView to display the evaluated value of CH1Label or CH2Label etc
So if ReportHeader.Channel = 4 then the value of [ReportHeader."Ch4Label"] should be rendered inside the MemoView
**Setting the text for MemoView dynamically in my Delphi code, before the report is printed works but I am wanting to simplify the code by moving this logic to FastReports

Fast Report's expression parser does not support nested expressions in the way you are trying to use them. As you only have the bundled Embarcadero version of Fast Reports, your only solution is to modify the memo view directly in your Delphi code or create a calculated field for the memoview component.
The paid for version of Fast Reports (Standard and up) support event handlers and scripting at the report component level, so if you wanted to keep the display logic in your report, then you could use scripting and use the OnBeforePrint event of the MemoView in question within the Fast Reports designer.

Related

Vaadin 23, converting inline Polymer template for grid columns renderes "NaN" instead of values

I am trying to convert some inline polymer templates for grid columns, and the rendered value in the browser ends up as “NaN” for some reason.
So I simplified the template to reproduce the issue as the following:
grid.addColumn(LitRenderer.<SamplePerson>of("<span style='${item.stylename-0}'> test </span>")
.withProperty("stylename-0", dto -> "background-color: red"));
and the rendered value still says style="NaN". Is there something that I’m missing?
Steps to reproduce the issue:
Go to https://start.vaadin.com and add a Master-Detail view from the existing templates to the views.
Download the application and open it in your favorite editor.
in the com.example.application.views.masterdetail.MasterDetailView's constructor, add the column with a LitRenderer (you can copy the above snippet code as well).
Run the application, go to http://localhost:8080 and observe that the values for the manually added column hasn't been styled with a red background. Obviously, by inspecting the elements you could see the style="NaN" is rendered on the client.
Tested with V23.2.3 and V23.2.4 and the issue exists.
Nicely spotted by #leif-Åstrand, this was an issue regarding the -0 ending, which was being parsed as a mathematical subtraction in JS, and clearly resulting in "NaN".
The correct way of doing this kind of dynamic class or style values ("stylename-0", "stylename-1", ...) is to treat them as strings, so:
style='${item.stylename-0}'
should be written as
style='${item['stylename-0']}'

DBText fields are shifted down when sending Report Builder report to Printer

I have a report template created in Report Designer. It is basically a RichText template with some DBText fields dropped on it. When I generate the report all the DBText fields are populated with data from database.
When I preview the generated report on screen it looks correct. But when I print the same report all DBText fields are shifted about one line down as on below screenshot:
If I remove RichText component and use only Labels and DBTexts then there is no problem with printing.
Has anybody faced the same issue in the past? How to solve it?
Note: I am using Delphi 5 with Report Builder 6.02 Enterprise.
As I found out the printing issue was caused by the RichText component used together with DBTexts components in the designer. It looks like Report Builder issue but I found two solutions for that:
You can remove RichText component from the template and use only Latels, DBTexts, etc. Printing will be fine in this case.
If you want to keep using RichText then you need to embed database fields inside the RichText Editor using angle brackets. You can see the example below:
Note, that it will only work when the “MailMerge” option is ticked (right click on the RichText component):
There is one limitation though. You can use only one dataset per report. However this can be solved by using subreports as for every subreport you can assign a different dataset (via Report -> Data menu).

Example on how to create HTML for THTMLViewer at runtime

With Delphi XE I've installed THTMLViewer. I see plenty of examples on how to read an HTM file (LoardFromFile) and display it in the Viewer. What I want to do is create the HTM at runtime in my program. If I had a RichEdit component I would have several SelText := lines.
Of course I can add lines to a stringlist, then SavetoFile the stringlist and finally LoadFromFile into htmlViewer, but that seems like an unnecessary extra step.
Is there a Memo.Lines or some other property of THtmlViewer where I can Add the desired lines of HTML coding?
If you are using a version of the component that supports it then LoadFromString would probably be the simplest function to use.
I am surprised that you didn't find that in the source. As I seem to recall it being available for some time.
If you need a newer version of the component source you can find it here: THTMLViewer Project

Creating macros using DWScript

I read this paragraph from the Delphi Tools Site
Changes since the last SVN update are:
Added support for FreePascal-like compile-time $INCLUDE “macros”:
%FILE% and %LINE% insert the current filename and line number into the source
%FUNCTION% inserts the current function name, or class.method name into the source
%DATE% and %TIME% allow inserting the compile date/time
Is there a way we can define macros in DWScript (other than these functions) just like people define macors in excel (using VBscript) in a simple way, where the name of the script will be the name of the function that will be used later, without adding {$Include XXX} in the executed script?
N.B.: I konw this can be done by managing the written script to be saved in a certain file called functions for ex. then save the added function with its name to be used (Add), then the user will write Add(1,2) to get the result; but my boss at work wants it to be something that looks like vbscript in excel.
I'm not sure to understand the question, so I'll list various answers to various possible interpretations...
If you want to declare functions that are implicitly supported by the scripting engine without having to "{$include}" or "uses" them, you can declare them via a TdwsUnit component, and attach it to the script component. If you don't have the "coExplicitUses" option set, they'll be available automatically, and you get design-time support in the IDE.
If you want to add internal functions (that are always there), use one of the RegisterInternalFunction overloads, you can check any of the "dwsXxxxFunctions.pas" units for examples. That's potentially more efficient, but also more cumbersome.
If you want to pre-process custom source-level macros in the source code (ala C's macros), you can use the filters functionality (check the HTML or JS filters as example of how a filter can be implemented).
If you want to react dynamically to "unknown" names, so you can declare them on the spot or bind them to something dynamically, you can use TdwsLanguageExtension.FindUnknownName, that's how the RTTI environment works f.i. (see TRTTIEnvironment in dwsRTTIConnector).
If you want to parse completely custom areas of code in a completely custom way, you can use language extensions too, override ReadInstr and check how asmLib & the JSLibModule do it to support "asm".

How I can add some items to the code completion combobox of the Delphi IDE

I'm working in a Delphi IDE expert and I wonder if it's possible add new items to the code completion combobox displayed by the Delphi IDE when the user press CtrlSpace
UPDATE:
What I need is add items to the code completion list based in a specified type.
example suppose which I have a type called TMytype, what I want to do is add addional items to the code completion list when the user type a variable of the type TMytype
check this image
I found your question somewhat confusing but if you are in search of credible source on "Custom Live Templates" and the like on Delphi, head to the blog of Cary Jensen here.
Edit:
Looking forward to further improvement of the scope of the question, I suggest here another direction to explore:
Source code manipulation using IOTAEditor, IOTASourceEditor, IOTAEditReader and the like
Some Parsing for sanity check prior to apply any modification.
Adoption of Client DataSet as a format to store data (It's serializable) to simplify the coding of IDE editors.
Perhaps I haven't fully grasped the extent of what you are asking here, but you can add templates simply by going to 'View|Templates' from the Delphi IDE. This then opens a template viewer. Press the '+' icon. It opens a template1.xml document which you can then edit so create your new item.
If you wish to do this programatically, just add an xml file (of the same format) to the ..\RAD Studio\code_templates folder.

Resources