#1 2020-10-22 14:34:53

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Why TTextWriter.AddLine supports shortstring only?

@ab,

I noticed the `TTextWriter.AddLine` method is defined as:

TTextWriter.AddLine(const Text: shortstring)

Why `shortstring` which is limited to 255 characters but not `RawUtf8`?


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#2 2020-10-22 15:48:20

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,673
Website

Re: Why TTextWriter.AddLine supports shortstring only?

It has a benefit of using a single method for shortstring, which can be written directly into the memory buffer, whereas it is not possible with a RawUTF8.
Just call AddCR or AddCRAndIndent after appending the RawUTF8.

Offline

#3 2020-10-22 17:33:09

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: Why TTextWriter.AddLine supports shortstring only?

Sorry, but it's still not clear to me if I can pass a RawUTF8 string to the AddLine method? It compiles, and is it really OK? Thanks!


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#4 2020-10-22 18:55:47

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,673
Website

Re: Why TTextWriter.AddLine supports shortstring only?

No, it is not OK since it will truncate the output to 255 characters.

Offline

#5 2020-10-23 05:47:45

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: Why TTextWriter.AddLine supports shortstring only?

OK, had to add a 'class helper' for TTextWriter, like the following:

procedure TTextWriterHelper.AddUtf8Line(const aLine: RawUtf8);
begin
  self.AddString(aLine);
  Self.AddCR;
end;

Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

Board footer

Powered by FluxBB