FastReport Delphi Preview fails when printing in a loop - printing

I have a function that prints a report for each selected item in a grid.
If I use preview without prepare it works but if I use prepare only the first report is printed. All the rest gives an empty report.
I create the report dynamically also the dataset is created dynamically. All components are freed at the end and recreated at the next report.
If I print all items one by one it works.
What happens in the prepare function, what can I do to avoid this?
I use FR5 and Delphi XE6 on windows10

If you create composite report - call TfrxReport.PrepareReport(True) on the first loop, TfrxReport.PrepareReport(False) on the next loops

Related

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).

Special case: wrong order of updates for fly-away

How can I track down the location of the "Special case: wrong order of updates for fly-away!" error?
This error message is defined in Datasnap.DSIntf as
const
...
ERRCODE_FLYAWAY_WRONGORDER = 13; { Special case: wrong order of updates for fly-away }
...
DBERR_FLYAWAY_WRONGORDER = ERRBASE_ALC + ERRCODE_FLYAWAY_WRONGORDER;
but nowhere else in the Delphi sources can I find references to substring FLYAWAY_WRONGORDER.*
My intention was to compile with debug dcu's, then put a breakpoint on the line where the exception is raised and check the call stack UP to find the cause.
I'm currently stepping DOWN into the code until the error occurs, but that is less efficient (complex app).
Placing a TApplicationEvents with a breakpoint in its OnException handler does not give me usable call stack information:
So, how can I (efficiently) track down the place where this error is generated?
Background on what is going on:
Form uses DevExpress TcxScheduler connected to TcxSchedulerStorage component in datamodule, connected to nested TClientDataSets
Code saves all changes to these datasets (ApplyUpdates)
In BeginUpdate/EndUpdate for these DevExpress components, I then insert, delete and update records in these datasets, move around while doing so, even change parent IDs in detail datasets so that they drop from the current detail dataset 'in view'.The error occurs when I Edit, then Post a record doing exactly that.
Delphi Tokyo 10.2.3, Win32 app
Any other info on that error message is welcome, I was not able to find anything.
I actually 'fixed' the error by calling ApplyUpdates for the master dataset in a few places, but since I'm not really sure about the cause I want to investigate this further. So my question is not How do I fix the error in my code, it is How do I find the error in my code?
* There is a CheckForFlyAway routine in TCustomADODataSet.InternalPost in Data.Win.ADODB but we don't use ADO, I cannot set breakpoints in those routines.

Delphi 2010 - Watchfolder - Check if a file is in use - Add item to listbox while the listbox is in loop

I'm trying to make a watchfolder application using Delphi 2010.
On the main form I added 2 listbox and a timer.
I list all files from a specific folder.
At every 5 seconds i perform a check over the files from a listbox to see which file is still in use.
Listbox1 holds the files that are in use and listbox2 holds the files that are not in use.
If there is a file that is being used(ex: it is still being copied to the folder) i add it to listbox1.
If the files from that folder that i monitor are not in use then I add them to listbox2.
The problem is that I perform a loop over listbox2 in order to send all the files listed to a ftp (for i:=0 to listbox2.items.count-1 do ....).
If i add one more file to listbox2 while performing the loop I get the "List index out of bounds"?
How can i add an item to listbox2 loop while performing the loop?
Thanks a lot?
Any other suggestion regarding the watchfolder ideea?
A for loop's control value is evaluated only once, at the beginning of the loop. Adding entries to the list should not be causing a bounds error, as the Count will not be shrinking. The loop will stop when it reaches the old Count. However, removing an item would shrink the Count and thus cause a bounds error once the loop exceeds the new Count trying to reach the old Count.
That being said, the solution is simple - DO NOT modify the ListBox while you are looping through its content! You will have to either:
delay any modifications until after the loop has finished.
copy the current ListBox content to a separate TStringList and loop through that instead of the ListBox directly, then you can do whatever you want to the ListBox while the loop is busy.

Delphi FastReport Nested Expression in MemoView

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.

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