CR+LF TRichEdit to TRichView
Posted: Sat Jan 28, 2006 10:22 pm
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;
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
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;
////////////////////////////////////////////////////////////////////////////////////