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;
////////////////////////////////////////////////////////////////////////////////////
CR+LF TRichEdit to TRichView
-
- Posts: 2
- Joined: Sat Jan 28, 2006 10:06 pm
CR+LF TRichEdit to TRichView
Last edited by Shinichiro on Sat Jan 28, 2006 11:13 pm, edited 1 time in total.
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Posts: 2
- Joined: Sat Jan 28, 2006 10:06 pm
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
The simplest way is to call AddURL for each line.
(do not call Format each time before executing this code, it not necessary, and only slows it down)
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;