I want to create a string spanning multiple lines to assign to the property Caption
of a TLabel
in Delphi:
Label1.Caption = 'Hola' + ?? + 'Mundo';
And visually it remains:
Hola
Mundo
How do I manage to do it in Delphi?
I want to create a string spanning multiple lines to assign to the property Caption
of a TLabel
in Delphi:
Label1.Caption = 'Hola' + ?? + 'Mundo';
And visually it remains:
Hola
Mundo
How do I manage to do it in Delphi?
The unit
System.pas
(which is automatically used by any Delphi unit) has the following definition:The code is taken from Delphi 10.2 Rio, but there is an equivalent mapping in all versions starting with Delphi 6 (approximately).
Using this constant ensures that the correct line break will be added for the platform the executable is compiled on.
So, to make a
TLabel
have two lines, make sure it has theAutoSize
en propertyTrue
, and then use code similar to the following:With information from this answer .
Simply in the middle of the sentence a char(13) is added:
Example :
Label1.Caption := 'Hola' + char(13)+ 'Mundo';
hello
world