In c# you can use multiline literal strings to have a string which spans a physical line break in the sourcecode e.g.
var someHtml = @"<table width="100%" border="0" cellspacing="0" cellpadding="5" align="center" class="txsbody">
<tbody>
<tr>
<td width="15%" class="ttxb"> </td>
<td width="85%" class="ttxb"><b>COMPANY NAME</b></td>
</tr>
</tbody>
</table>";
but how to do this in delphi without using string concatenation, not so much for performance but for looking visually as nice as in c# instead of
Result : = '<table width="100%" border="0" cellspacing="0" cellpadding="5" align="center" class="txsbody">';
Result : Result + '<tbody>';
Use triple quotes to create a multiline string It is the simplest method to let a long string split into different lines. You will need to enclose it with a pair of Triple quotes, one at the start and second in the end. Anything inside the enclosing Triple quotes will become part of one multiline string.
Three single quotes, three double quotes, brackets, and backslash can be used to create multiline strings.
A verbatim string literal consists of an @ character followed by a double-quote character, zero or more characters, and a closing double-quote character. Not only does this allow multiple lines, but it also turns off escaping.
So if you want to make your TLabel wrap, make sure AutoSize is set to true, and then use the following code: label1. Caption := 'Line one'+sLineBreak+'Line two'; Works in all versions of Delphi since sLineBreak was introduced, which I believe was Delphi 6.
How to do this in delphi without using string concatenation?
You cannot. There is no support for multi-line literals. Concatenation is the only option.
However, your Delphi code performs the concatenation at runtime. It's far better to do it at compile time. So instead of:
Result := 'foo';
Result := Result + 'bar';
write
Result := 'foo' +
'bar';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With