Crossplatform new line character

I need to split a caption of a TCheckBox in two lines at a specific place.
So, I set CheckBox1.WordWrap to True, adjust its height and sofar OK, if the text is long enough,
it wraps to a second line.

Q1: I can't figure out how to enter a carriage return, line feed or both in the object inspector.
Is it possible?

A workaround is to define a string const:
const
  CR = #$0D;
  cbCaption = 'The text that needs to' + CR + 'wrap around';
and then in the forms OnCreate assign it to CheckBox1.Caption

I also tested with LF = #$0A and CRLF = CR + LF, and on Windows all of these work.

Q2: For compatibility with possible future crossplatform porting of the code (to OSX, iOS and
Android), which new line character would be best, CR, LF or CRLF?

-- 
Tom Brunberg
[email protected]
0
Tom
4/2/2014 10:04:48 AM
📁 embarcadero.delphi.general
📃 4258 articles.
⭐ 0 followers.

💬 8 Replies
👁️‍🗨️ 3077 Views

Tom Brunberg wrote:

> Q1: I can't figure out how to enter a carriage return, line feed or
> both in the object inspector.

Have you tried copy/paste multiline text from some external editor?

JVCL has custom editor for string properties in OI. It adds [...]
button which shows an editor like Memo.Lines. After editing multiline
text has new line chars (0a+0d) which look as squares in OI.

-- 
Alex
0
Alex
4/2/2014 10:19:16 AM
Tom Brunberg wrote:

> I need to split a caption of a TCheckBox in two lines at a specific
> place.  So, I set CheckBox1.WordWrap to True, adjust its height and
> sofar OK, if the text is long enough, it wraps to a second line.
> 
> Q1: I can't figure out how to enter a carriage return, line feed or
> both in the object inspector.  Is it possible?

For a regular caption that doesn't let you enter multiple lines, you
could edit the .dfm (view as text), enter the text with the line breaks
directly and then switch back (View as Form).

Caption = 'The text that needs to'#13#10'wrap around'


> A workaround is to define a string const:

Given the choice, I would probably do it this way.


> Q2: For compatibility with possible future crossplatform porting of
> the code (to OSX, iOS and Android), which new line character would be
> best, CR, LF or CRLF?

Use the constant "sLineBreak", which takes care of this for you.

-- 
Regards,
Bruce McGee
Glooscap Software
0
Bruce
4/2/2014 11:22:12 AM
Alex Belo wrote:

> Tom Brunberg wrote:
> 
> > Q1: I can't figure out how to enter a carriage return, line feed or
> > both in the object inspector.
> 
> Have you tried copy/paste multiline text from some external editor?

Thanks Alex. No, I haven't, until now.
It would have been too simple :), unfortunately it doesn't work. It seems the IDE cuts off the
second line (in D2010, I did not try with XE5)

> JVCL has custom editor for string properties in OI. It adds [...]
> button which shows an editor like Memo.Lines. After editing multiline
> text has new line chars (0a+0d) which look as squares in OI.

That would be a nice feature

-- 
Tom Brunberg
[email protected]
0
Tom
4/2/2014 2:34:39 PM
Bruce McGee wrote:

> Tom Brunberg wrote:
> 
> > I need to split a caption of a TCheckBox in two lines at a specific
> > place.  So, I set CheckBox1.WordWrap to True, adjust its height and
> > sofar OK, if the text is long enough, it wraps to a second line.
> > 
> > Q1: I can't figure out how to enter a carriage return, line feed or
> > both in the object inspector.  Is it possible?
> 
> For a regular caption that doesn't let you enter multiple lines, you
> could edit the .dfm (view as text), enter the text with the line breaks
> directly and then switch back (View as Form).
> 
> Caption = 'The text that needs to'#13#10'wrap around'

Thanks Bruce. Ah yes, didn't think of that.

> > A workaround is to define a string const:
> 
> Given the choice, I would probably do it this way.
> 
> 
> > Q2: For compatibility with possible future crossplatform porting of
> > the code (to OSX, iOS and Android), which new line character would be
> > best, CR, LF or CRLF?
> 
> Use the constant "sLineBreak", which takes care of this for you.

Thanks for that, I didn't know it existed. Found it now in System.pas (XE5) defined as
_AnsiChar(#10) on POSIX and _AnsiStr(#13#10) on MSWINDOWS.

What does POSIX actually stand for? OSX and LINUX?
How do _AnsiChar and/or _AnsiStr work on mobiles?


-- 
Tom Brunberg
[email protected]
0
Tom
4/2/2014 2:34:40 PM
Tom Brunberg wrote:

> What does POSIX actually stand for? OSX and LINUX?

Here are the predefined conditionals and which platforms they are
defined on.  Basically, everything that isn't Windows.

http://docwiki.embarcadero.com/RADStudio/XE5/en/Conditional_compilation_%28Delphi%29


> How do _AnsiChar and/or _AnsiStr work on mobiles?

I don't know.

-- 
Regards,
Bruce McGee
Glooscap Software
0
Bruce
4/2/2014 4:27:48 PM
Bruce McGee wrote:

> Tom Brunberg wrote:
> 
> > What does POSIX actually stand for? OSX and LINUX?
> 
> Here are the predefined conditionals and which platforms they are
> defined on.  Basically, everything that isn't Windows.
> 
> http://docwiki.embarcadero.com/RADStudio/XE5/en/Conditional_compilation_%28Delphi%29

Thanks Bruce!

> > How do _AnsiChar and/or _AnsiStr work on mobiles?
> 
> I don't know.

OK, I'll find out later.

Cheers

-- 
Tom Brunberg
[email protected]
0
Tom
4/2/2014 5:29:46 PM
> {quote:title=Tom Brunberg wrote:}{quote}

> What does POSIX actually stand for? OSX and LINUX?

POSIX stands for "Portable Operating System Interface" and is a collection of standards to allow compatibility across different operating systems. OS/X is fully POSIX compliant and Linux is mostly POSIX compliant depending on the distro. Windows, of course, is the oddball out as usual :-). That said, Cygwin can give you a mostly POSIX-compatible environment on Windows and Microsoft makes a similar product (SFU).
0
Joseph
4/2/2014 6:20:44 PM
Joseph Mitzen wrote:

> > {quote:title=Tom Brunberg wrote:}{quote}
> 
> > What does POSIX actually stand for? OSX and LINUX?
> 
> POSIX stands for "Portable Operating System Interface" and is a collection of standards to allow
> compatibility across different operating systems. OS/X is fully POSIX compliant and Linux is
> mostly POSIX compliant depending on the distro. Windows, of course, is the oddball out as usual
> :-). That said, Cygwin can give you a mostly POSIX-compatible environment on Windows and
> Microsoft makes a similar product (SFU).

Thanks Joseph for the information.

-- 
Tom Brunberg
[email protected]
0
Tom
4/3/2014 12:36:37 PM
Reply: