Using SysUtils.WrapText() with strings containing single quotes

What you describe is intentional behavior.

In Delphi XE and earlier, the WrapText() documentation included this statement:

WrapText does not insert a break into an embedded quoted string (both single quotation marks and double quotation marks are supported).

In Delphi XE2 onwards, that statement is omitted from the documentation, but the behavior is still implemented in the RTL.

I have opened a ticket with Embarcadero about this omission:

RSP-24114: Important clause about embedded quoted strings is missing from WrapText documentation


In 10.3.1 the source includes code for handling quote characters, both double and single quotes, which looks to just ignore text between them. So one solution would be to use an apostrophe that is different from the single quote character. A second would to be to avoid using contractions. The start of the function source:

function WrapText(const Line, BreakStr: string; const BreakChars: TSysCharSet;
  MaxCol: Integer): string;
const
  QuoteChars = ['''', '"'];
  FirstIndex = Low(string);
  StrAdjust = 1 - Low(string);
var
...

One option:

    Lines.Text := WrapText('Can`t format message, message file not found', 15);

A second option:

    Lines.Text := WrapText('Cannot format message, message file not found', 15);