Jump to content
Sign in to follow this  
shineworld

Add #13#10 to a string

Recommended Posts

It is embarrassing but I was not able to set a multiline text in a Button Caption.

Usually in Delphi is only necessary to:

MyButton.Caption = 'first line' + #13#10 + 'second line'

What to get same behaviour in Python + DelphiVCL ?
 

Share this post


Link to post

In Python a \n usually does the trick. As per your example:

caption = 'First line \n second line'

Note that there is no need to concatenate the string.

  • Like 1

Share this post


Link to post
1 hour ago, Sherlock said:

Note that there is no need to concatenate the string.

As an aside, even in Delphi there is no such need. You can write

'first line'#13#10'second line'

And even then, concatenation of literals is performed by the compiler, so the above code would result in the same codegen as

'first line' + #13#10 + 'second line'

Finally, it is usually preferable to use sLineBreak rather than #13#10 so that your code is more expressive, and platform independent.

  • Like 2

Share this post


Link to post

Thanks for the replies.

I've also missed to set WordWrap to True in button properties 🙂

Happens!

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×