Ali Dehban 38 Posted February 1 I'm maintaining an aged legacy application written in Delphi. I'm experiencing something weird in a report made by Fastreport (ver 5.5.6) and Delphi (XE5). There is a situation in which the exe will be triggered with some input parameters to export the expected document to PDF or Image to be used on a website or somewhere. The specific report that I'm talking about has some fields that are formatted by Pascal script to 24-Hour format or AM/PM to meet each customer's needs. (Dynamic report). Everything is perfect in the report preview, the printed report, and export to PDF, image, or Excel in the visible mode of the application(normal usage of the application). but those formats don't apply in invisible mode, those fields come up with the default format of the server. I checked the SQL Server result and the application report preview in visible mode and everything is fine but on the same machine when it executes in invisible mode it doesn't work. I doubted those Pascal scripts (OnAfterData event has been used), so I put some log functions and I realized those Pascal scripts are running, I can verify they are running each time but don't affect the final exported file. Does anybody have the same experience, Any advice? Share this post Link to post
Cristian Peța 103 Posted February 1 22 minutes ago, Ali Dehban said: but those formats don't apply in invisible mode What is invisible mode? A Windows service? 23 minutes ago, Ali Dehban said: The specific report that I'm talking about has some fields that are formatted by Pascal script to 24-Hour format or AM/PM to meet each customer's needs. Can you show the code of that script? Share this post Link to post
Cristian Peța 103 Posted February 1 Are the script code using regional settings? Do you need the user to decide the format? Share this post Link to post
Ali Dehban 38 Posted February 1 (edited) 1- Invisible means running the exe in the command line with some input parameters to do a certain job and terminate with no UI (Application.ShowMainForm := False) Note: Do not ask me to change it to a Windows service or web service, etc, I wish I could but it's not possible because I'm not the owner of the product and it should work as is by their command; 2- And this is the script: procedure XReportOnAfterData(Sender: TfrxComponent); var LvTimeValue: string; LvLength: Integer; begin if Sender is TfrxMemoView then begin LvTimeValue := Trim(TfrxMemoView(Sender).Text); LvLength := Length(LvTimeValue); if LvLength > 0 then begin try TfrxMemoView(Sender).Text := FormatDateTime('HH:mm', StrToDateTime(LvTimeValue)); except TfrxMemoView(Sender).Text := 'Error: N/A'; end; end; end; end; Thank you for your response by the way. Edited February 1 by Ali Dehban Share this post Link to post
Cristian Peța 103 Posted February 1 (edited) You want to change the text value from a frxMemoView from date-time to display hour and minutes? Because mm is month... and HH is not documented. See documentation: https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.SysUtils.FormatDateTime EDIT: Now I see that mm can show minuts if after hh. Edited February 1 by Cristian Peța 1 Share this post Link to post
Cristian Peța 103 Posted February 1 What value is in that frxMemoView text before change and what after? Share this post Link to post
Ali Dehban 38 Posted February 1 1 hour ago, Cristian Peța said: What value is in that frxMemoView text before change and what after? The value is pure TDateTime. The desired format would be 'hh:nn'. But this 'HH' is a mistake I think (the support team did or myself during tests) and I just copied the current script without more checks, I'm not sure how and when this happened and why it is still working in UI mode. Thank you for the hint, I will investigate more and inform you about it, further. Share this post Link to post
Cristian Peța 103 Posted February 1 1 hour ago, Ali Dehban said: The value is pure TDateTime. It is as text and it must be formatted like regional settings because you are using StrToDateTime() to convet this text to TDateTime. Share this post Link to post
Ali Dehban 38 Posted February 1 1 minute ago, Cristian Peța said: It is as text and it must be formatted like regional settings because you are using StrToDateTime() to convet this text to TDateTime. Sure, I mean the retrieved data field from the database is TDateTime, but when you read from a TfrxMemoView you'll get it as text. Share this post Link to post
Cristian Peța 103 Posted February 1 That field is not read by MemoView? Why convert it to String then again to TDateTime? In script you can use <MyTable."MyDateTimeField"> to read it as Variant that will keep TDateTime as it is (actually a Double). 1 Share this post Link to post
Ali Dehban 38 Posted February 1 You are right, It's designed by the customer itself, and the designer used IIF() to fill the MemoView to select one from two available TdateTime fields by some conditions and the result of IIF is text. Share this post Link to post
Ali Dehban 38 Posted February 2 20 hours ago, Cristian Peța said: You want to change the text value from a frxMemoView from date-time to display hour and minutes? Because mm is month... and HH is not documented. See documentation: https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.SysUtils.FormatDateTime EDIT: Now I see that mm can show minuts if after hh. It seems "mm" is defined in the fast report format options for minute, what does it mean "hh:mm" in fast report equals "hh:nn" in Delphi likely. Share this post Link to post
Cristian Peța 103 Posted February 2 I said before that mm represents also minutes if after hh. It states in documentation: mm Displays the month as a number with a leading zero (01-12). If the mm specifier immediately follows an h or hh specifier, the minute rather than the month is displayed. Share this post Link to post