How to use sLineBreak from the object inspector?

1.2k Views Asked by At

Currently, I'm setting a string which contains sLineBreak constant as value for the Caption property of a TLabel control.

MyLabel.Caption := 'A' + sLineBreak + 'B';

sLineBreak is defined in System.pas as follows (Delphi 2007):

const
      sLineBreak = {$IFDEF LINUX} #10 {$ENDIF} {$IFDEF MSWINDOWS} #13#10 {$ENDIF};

Is there a way to do the same thing by using the object inspector? (At design time).

Update: Probably in future I will move this project to a newer IDE and will develop on different platforms, but at the moment there's no particular reason why I'm using sLineBreak instead of #13#10. I'm sorry for misunderstanding.

3

There are 3 best solutions below

10
On BEST ANSWER

You cannot use the sLineBreak constant at design-time. However, you can either:

  1. Edit the DFM directly (right-click the Form Designer and choose View as Text) to insert CR/LF characters into the encoded Caption text, eg:

    Using a bare-LF line break

    object MyLabel: TLabel
      Caption = 'A'#10'B'
    end
    

    Using a CRLF line break

    object MyLabel: TLabel
      Caption = 'A'#13#10'B'
    end
    
  2. Install a third party design-time property editor (or write your own) that allows multi-line editing of String property values. For example, "Extended String Property Editor".

0
On

No, the Object Inspector doesn't evaluate variables at design time.

The usual way to work around this is to set the caption in the form's constructor:

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyLabel.Caption := 'A' + sLineBreak + 'B';
end;
0
On

I am assuming that you wish to do this in a cross-platform setting, in which case it cannot be done. Form files do not have any mechanism for conditional value specification. You should apply the value at runtime.