skip to Main Content

Usually one would set it like this at runtime:

Label1.Caption := 'First line' + #13#10 + 'SecondLine';

but for some reason, this does not seem to work even if you turn WordWrap on or off.

What is the solution to create a linebreak in TMS Web Core at runtime?

2

Answers


  1. Chosen as BEST ANSWER

    Found a better solution: In Design Time view the dfm as text

        object lblSection: TWebLabel
          AlignWithMargins = True
          Left = 0
          Top = 75
          Width = 1454
          Height = 136
          Margins.Left = 0
          Margins.Top = 75
          Margins.Right = 0
          Margins.Bottom = 0
          Align = alTop
          Alignment = taCenter
          Caption = 'Line1'#13'Line2'
          Font.Charset = ANSI_CHARSET
          Font.Color = clWindowText
          Font.Height = -28
          Font.Name = 'Sans Serif Collection'
          Font.Style = []
          HeightPercent = 100.000000000000000000
          HTMLType = tDIV
          ParentFont = False
          WidthPercent = 100.000000000000000000
          ExplicitWidth = 567
        end
      end
    end
    

    so you need to use #13 between Line1 and Line2. Seems like you cannot use #10 in TMS

    This answer helped me: https://stackoverflow.com/a/36641512/19420461


  2. First note. You can use sLineBreak instead of #13#10. sLineBreak is a constant defined in the System unit:

    const
       sLineBreak = {$IFDEF POSIX} _AnsiStr(#10) {$ENDIF}
           {$IFDEF MSWINDOWS} _AnsiStr(#13#10) {$ENDIF};
    

    I tested linebreaks on TMS Web Core on my side. It seems like the TWebLabel doesn’t support a linebreak (#13#10) in it for some reason. It does work in other controls such as a TWebMemo.

    I did a test. Here’s me trying to add it to a TWebLabel and a TWebMemo and you can see it working on the Memo, but not on the Label:

    WebLabel1.Caption := 'First line' + sLineBreak + 'SecondLine';
    WebMemo1.Text := 'First line' + sLineBreak + 'SecondLine';
    

    Button, Label, Memo


    There is however a way. You can use the following:

    WebLabel1.ElementHandle.innerHTML := 'First line' + '<br>' + 'SecondLine';
    

    The <br> is the linebreak and that works:

    Button, Label, Memo

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search