I use a TAdvRichEditor to enable my used to edit a DESCRIPTION field as Raw Text or as HTML.
When I set my form in "Raw Text" mode, I use the "Text" property to Get and Set the content as lines of not formatted text.
When I edit the same text twice, the newlines are doubled. This is due to a bug in procedure TAdvRichEditorBase.AddMultiLineText(AValue: string);
It processes a #13
by adding a NewLine and cleaning the t
variable. The it encounters a #10
, as it was preceded by a #13
is does not add a NewLine but the #10
char is appended to the t
variable.
Thus, the saved text contains normal NewLines (#13#10
) dans duplicated #10
This version seems to work (I also added a const
to the param definition)
procedure TAdvRichEditorBase.AddMultiLineText(const AValue: string);
var
t: string;
i, l: Integer;
ch, pch: string;
begin
i := 1;
t := '';
pch := '';
l := Length(AValue);
while i <= l do
begin
ch := Copy(AValue, i, 1);
if (ch = #10) then
begin
if (t <> '') then
AddText(t);
AddLineBreak;
t := '';
end
else if (ch = #9) then
begin
if (t <> '') then
AddText(t);
if WantTab then
AddTab
else
AddText(' ');
t := '';
end
else if (ch <> #13) then // just ignore #13
t := t + ch;
inc(i);
pch := ch;
end;
if (t <> '') then
AddText(t);
UpdateSize;
Refresh;
end;
EDIT 1 : The #13
char must always add a NewLine, even if the previous char was a #10
otherwise multiple newlines gets trimmed.
EDIT 2 : Simplified : Just ignore #13
and always add NewLines on #10
We cannot just ignore #13. #13 should be treated as a new line as in many cases, text will just have #13 to set linebreaks.
Do you always have both #13#10 as linebreak?
What exactly means "set my form in raw text mode"?
Which platform uses #13 as line breaks ?
To answer your question, I have a checkbox to force return the text as "raw text" instead of HTML.
A Windows text file can be fine with just #13 for example.
Ok, but what does this checkbox invoke in code
Sorry
function TFrmAdminHTML.GetData: string;
var
S: TStringStream;
begin
if cbPlainText.Checked then
Result := reDescription.Text { RAW TEXT MODE }
else
begin
{ HTML MODE }
S := TStringStream.Create('', TEncoding.UTF8);
try
ioHTML.Save(S);
Result := S.DataString;
finally
S.Free;
end;
end;
end;
And I think SetData()
is worth to be shown too :
procedure TFrmAdminHTML.SetData(const Value: string);
begin
if Pos('<FONT', Value) = 0 then
begin
reDescription.Text := Value;
cbPlainText.Checked := True;
end
else
ioHTML.LoadHTML(Value);
end;
I cannot reproduce this.
Project1.zip (52.4 KB)
Just made a video to show the problem
The sources of this demo app :
AdvRichEditor.zip (8.5 KB)
You just need to open the editor once, add two lines, close the editor and open the editor one or two more time to see that random NewLines (in fact #10) are added.
Cannot be compiled. Contains units & components not standard VCL and not TMS units.
Please cleanup all non standard and non TMS units / classes.
Done as rerquired,
AdvRichEditor.zip (91.5 KB)
I cannot reproduce a problem

Sad.
Try this :
- Start the app, click "Open Editor"
- Add a line and a NewLine, so you get something like :
MainMemo[#13#10]
Second Line[#13#10]
- Close editor (the checkbox should be checked)
- Open the editor again
A blank line should have appeared between the two lines.
I'm sorry. It isn't here.
Are you 100% sure you use the latest version?
I'm usging v12.1.0.0 and can't update right now (in a process of finalizing a production release)
Before posting this issue, I checked the Changelog and saw nothing related to how AdvRichEditor handles SetText.
Or, maybe, this was fixed here ?
I suggest to try on a separate machine with the latest version.