Recent

Author Topic: LCLTaskDialog prevent \n conversion to LF  (Read 2099 times)

zamtmn

  • Hero Member
  • *****
  • Posts: 594
LCLTaskDialog prevent \n conversion to LF
« on: March 26, 2021, 08:44:49 pm »
is there a way to disable this conversion?
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   LCLTaskDialog;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.Button1Click(Sender: TObject);
  34. var
  35.   td: TTaskDialog;
  36. begin
  37.   td.Content:='Save "c:\new_folder\new.work"?';
  38.   td.Execute;
  39. end;
  40.  
  41. end.

dsiders

  • Hero Member
  • *****
  • Posts: 1080
Re: LCLTaskDialog prevent \n conversion to LF
« Reply #1 on: March 26, 2021, 09:01:07 pm »
is there a way to disable this conversion?
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   LCLTaskDialog;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.Button1Click(Sender: TObject);
  34. var
  35.   td: TTaskDialog;
  36. begin
  37.   td.Content:='Save "c:\new_folder\new.work"?';
  38.   td.Execute;
  39. end;
  40.  
  41. end.

That value gets passed to the Windows API, and it thinks '\n' is a new line. Have you tried quoting the backslash?

Code: Pascal  [Select][+][-]
  1. td.Content:='Save "c:\\new_folder\\new.work"?';

Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: LCLTaskDialog prevent \n conversion to LF
« Reply #2 on: March 26, 2021, 09:10:36 pm »
No, not works((
This done not in windows, probably have to add a setting that disables this

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: LCLTaskDialog prevent \n conversion to LF
« Reply #3 on: March 26, 2021, 09:16:34 pm »
I would call that a bug. \n has no meaning in pascal.

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: LCLTaskDialog prevent \n conversion to LF
« Reply #4 on: March 26, 2021, 09:20:13 pm »
I would call that a bug. \n has no meaning in pascal.

no, this documented in LCLTaskDialog
Quote
.........................
TTaskDialog = record
    /// the main title of the dialog window
    // - if left void, the title of the application main form is used
    Title: string;
    /// the main instruction (first line on top of window)
    // - any '\n' will be converted into a line feed
    // - if left void, the text is taken from the current dialog icon kind
    Inst: string;
    /// the dialog's primary content content text
    // - any '\n' will be converted into a line feed
    Content: string;
    /// a #13#10 or #10 separated list of custom buttons
    // - they will be identified with an ID number starting at 100
    // - by default, the buttons will be created at the dialog bottom, just
    // like the common buttons
    // - if tdfUseCommandLinks flag is set, the custom buttons will be created
    // as big button in the middle of the dialog window; in this case, any
    // '\n' will be converted as note text (shown with smaller text under native
    // Vista/Seven TaskDialog, or as popup hint within Delphi emulation)
    Buttons: string;
    /// a #13#10 or #10 separated list of custom radio buttons
    // - they will be identified with an ID number starting at 200
    // - aRadioDef parameter can be set to define the default selected value
    // - '\n' will be converted as note text (shown with smaller text under
    // native Vista/Seven TaskDialog, or as popup hint within Delphi emulation)
    Radios: string;
    /// the expanded information content text
    // - any '\n' will be converted into a line feed
    // - the Delphi emulation will always show the Info content (there is no
    // collapse/expand button)
    Info: string;
    /// the button caption to be displayed when the information is collapsed
    // - not used under XP: the Delphi emulation will always show the Info content
    InfoExpanded: string;
    /// the button caption to be displayed when the information is expanded
    // - not used under XP: the Delphi emulation will always show the Info content
    InfoCollapse: string;
    /// the footer content text
    // - any '\n' will be converted into a line feed
    Footer: string;
    /// the text of the bottom most optional checkbox
    Verify: string;
    /// a #13#10 or #10 separated list of items to be selected
    // - if set, a Combo Box will be displayed to select
    // - if tdfQuery is in the flags, the combo box will be in edition mode,
    // and the user will be able to edit the Query text or fill the field
    // with one item of the selection
    // - this selection is not handled via the Vista/Seven TaskDialog, but
    // with our Delphi emulation code (via a TComboBox)
    Selection: string;
    /// some text to be edited
    // - if tdfQuery is in the flags, will contain the default query text
    // - if Selection is set, the
    Query: string;
...........................

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: LCLTaskDialog prevent \n conversion to LF
« Reply #5 on: March 26, 2021, 10:55:19 pm »
So then it is a documented bug ?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: LCLTaskDialog prevent \n conversion to LF
« Reply #6 on: March 27, 2021, 03:48:12 am »
So then it is a documented bug ?

I would call it an "unfortunate design decision" rather than a bug: it should either recognize "\\" as a escape mechanism or there should be a flag to disable it altogether. As it's, it will mangle any Windows path with directories starting with "n".

In that situation one could as well use Dialogs.TTaskDialog which (IIRC) doesn't present this behaviour.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: LCLTaskDialog prevent \n conversion to LF
« Reply #7 on: March 27, 2021, 05:18:43 pm »
I think this is a good solution:
Code: Pascal  [Select][+][-]
  1. Index: lcl/lcltaskdialog.pas
  2. ===================================================================
  3. --- lcl/lcltaskdialog.pas       (revision 64866)
  4. +++ lcl/lcltaskdialog.pas       (working copy)
  5. @@ -129,7 +129,7 @@
  6.    {$IFDEF MSWINDOWS}
  7.    Windows,
  8.    {$ENDIF}
  9. -  Classes, SysUtils,
  10. +  Classes, SysUtils, StrUtils,
  11.    LazUTF8,
  12.    LCLType, LCLStrConsts, LCLIntf, InterfaceBase,
  13.    LResources, Menus, Graphics, Forms, Controls, StdCtrls, ExtCtrls, Buttons;
  14. @@ -563,9 +563,9 @@
  15.  
  16.  function CR(const aText: string): string;
  17.  begin
  18. -  if pos('\n', aText) = 0 then
  19. +  if pos('\', aText) = 0 then
  20.      result := aText else
  21. -    result := StringReplace(aText, '\n', #10, [rfReplaceAll]);
  22. +    result := StringsReplace(aText,['\\','\n'],['\',#10], [rfReplaceAll]);
  23.  end;
works with \n and \\

it is worth creating a bug report?
« Last Edit: March 28, 2021, 09:14:16 pm by zamtmn »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: LCLTaskDialog prevent \n conversion to LF
« Reply #8 on: March 27, 2021, 09:07:01 pm »
A good solution needs no escaping. An user can pass it well-formed pascal strings, and the widgetset-whatever code escapes it to pass to legacy OS services that expect escaping.

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: LCLTaskDialog prevent \n conversion to LF
« Reply #9 on: March 27, 2021, 11:24:38 pm »
I proceed from what is. I just added \\

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: LCLTaskDialog prevent \n conversion to LF
« Reply #10 on: March 28, 2021, 02:36:18 pm »
So you want to cripple the Window users?

what if I want all of that in there ?

tell me more, what do you mean?

A good solution needs no escaping. An user can pass it well-formed pascal strings, and the widgetset-whatever code escapes it to pass to legacy OS services that expect escaping.

If I were doing something new, I would do something new. Here you need to leave compatibility with existing code, but add new functionality

 

TinyPortal © 2005-2018