CR+LF TRichEdit to TRichView

General TRichView support forum. Please post your questions here
Post Reply
Shinichiro
Posts: 2
Joined: Sat Jan 28, 2006 10:06 pm

CR+LF TRichEdit to TRichView

Post by Shinichiro »

Please teach a method to CR+LF add TRichView

////////////////////////////////////////////////////////////////////////////////////
procedure AddURL(S: String; RV: TRichView; DefStyle, UrlStyle: Integer);
var
Before, CurrentWord, Space: String;
P: Integer;
begin
Before := '';

if S = '' then
begin
RV.Add('', DefStyle);
exit;
end;

while S <> '' do
begin
P := Pos(' ', S);
if P = 0 then
P := Length(S) + 1;

CurrentWord := Copy(S, 1, P-1);
Space := Copy(S, P, 1);
S := Copy(S, P+1, Length(S));

if URL(CurrentWord) or Email(CurrentWord) then
begin
if Before <> '' then
begin
RV.Add(Before, DefStyle);
Before := '';
end;

RV.Add(CurrentWord, UrlStyle);

if Space <> '' then
RV.Add(Space, DefStyle);
end
else
Before := Before + CurrentWord + Space;
end;

if Before <> '' then
RV.Add(Before, DefStyle);
end;

procedureTForm2.Button1Click(Sender: TObject);
var
Comment : String;
begin
Form1.RichView1.Format;
Comment := RichEdit1.text;
AddURL(Comment, Form1.RichView1, 0, 1);
Form1.RichView1.FormatTail;
end;
////////////////////////////////////////////////////////////////////////////////////
Last edited by Shinichiro on Sat Jan 28, 2006 11:13 pm, edited 1 time in total.
Sergey Tkachenko
Site Admin
Posts: 17315
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you want to modify this function to allow CR+LF in the S parameter?
Shinichiro
Posts: 2
Joined: Sat Jan 28, 2006 10:06 pm

Post by Shinichiro »

Yes, I want to modify this function to allow CR+LF in the S parameter.
What should it carry out?
Sergey Tkachenko
Site Admin
Posts: 17315
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

The simplest way is to call AddURL for each line.

Code: Select all

var p: Integer;
    Line, Comment: String;

Comment := AdjustLineBreaks(Comment);
repeat
  p := Pos(#13, Comment);
  if p=0 then begin
    Line := Comment;
    Comment := '';
    end
  else begin
    Line := Copy(Comment, 1, p-1);
    Comment := Copy(Comment, p+2, Length(Comment));
  end;
  AddURL(Line, Form1.RichView, 0, 1);
until Comment='';
Form1.RichView.FormatTail;
(do not call Format each time before executing this code, it not necessary, and only slows it down)
Post Reply