richedit的问题,急,请帮帮我.(100分)

  • 主题发起人 主题发起人 sqs
  • 开始时间 开始时间
S

sqs

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟在做一个程序的时候用richedit作为一个client的终端接受server的
信息.从server的信息里传来一些文本的信息串.这些信息串中包含着'aaa'
'bbb''ccc'这些字符串,我需要用richedit实现的功能是当碰到'aaa'的时
候就自动删除掉'aaa'当看到'bbb'的时候就删除掉'bbb'在把'bbb'后的字符
串改为红色,当看到'ccc'的时候删除掉'ccc'在把'ccc'后的颜色改为蓝色.

我在richedit里的onchange事件里加上
var
t , s : string;
i : intrger;
begin
t := 'aaa';
s := richedit.lines.text;
i := pos(t,s);
wile richedit do
if i>0 then
SelStart := FindText(t,0,GetTextLen,[stWholeWord]);
SelLength := 3;
SelText := '';
SelLength := 0;
end;
end;
但是如果aaa,bbb这类字符串多了就闪烁的很厉害,而且也删不干净,颜色用
SelAttributes.Color也设置不好.
我做过一个函数.但是不好用.我想请教delphi的richedit高手,这种问题如
何解决.万分感谢.

我只有100分了,我全给了.各位大侠帮帮我,感激不尽.


 

RichEdit.findText
试试看!
 
http://acgahqtv.home.china.com/delphi/delphiarticle/tec15.html
 
那里我以前就去过,大侠们能不能给个code看看,给大侠们鞠躬了.
 
procedure TForm1.RichEdit1Change(Sender: TObject);
var
s1,s2,s3: string;
i1,i2:integer;
begin
s1 := 'aaa';
s2 := 'bbb';
s3 := 'ccc';
richedit1.SetFocus;
richedit1.SelStart :=richedit1.FindText(s1,0,richedit1.GetTextLen,[stMatchCase]);
while richedit1.SelStart>=0 do
begin
richedit1.SelLength:=3;
richedit1.seltext:='';
richedit1.SelLength:=0;
richedit1.SelStart :=richedit1.FindText(s1,0,richedit1.GetTextLen,[stMatchCase]);
if richedit1.SelStart= richedit1.GetTextLen then break;
end;
i1 :=richedit1.FindText(s2,0,richedit1.GetTextLen,[stMatchCase]);
i2 :=richedit1.FindText(s3,0,richedit1.GetTextLen,[stMatchCase]);
if i1<i2 then richedit1.SelStart:=i1
else richedit1.SelStart:=i2;
while richedit1.SelStart>=0 do
begin
if i1<i2 then
begin
richedit1.SelStart :=richedit1.FindText(s2,0,richedit1.GetTextLen,[stMatchCase]);
richedit1.SelLength:=3;
richedit1.seltext:='';
richedit1.SelLength := richedit1.GetTextLen; // select the word
richedit1.SelAttributes.color:=clBlue;
richedit1.SelLength:=0; // de-select the word
i1 :=richedit1.FindText(s2,0,richedit1.GetTextLen,[stMatchCase]);
end
else
begin
richedit1.SelStart :=richedit1.FindText(s3,0,richedit1.GetTextLen,[stMatchCase]);
richedit1.SelLength:=3;
richedit1.seltext:='';
richedit1.SelLength := richedit1.GetTextLen; // select the word
richedit1.SelAttributes.color:=clRed;
richedit1.SelLength:=0; // de-select the word
i2 :=richedit1.FindText(s3,0,richedit1.GetTextLen,[stMatchCase]);
end;
if i1<i2 then richedit1.SelStart:=i1
else richedit1.SelStart:=i2;
if richedit1.SelStart= richedit1.GetTextLen then break;
end;
end;
 
奇怪
i1 :=richedit1.FindText(s2,0,richedit1.GetTextLen,[stMatchCase]);
i2 :=richedit1.FindText(s3,0,richedit1.GetTextLen,[stMatchCase]);
if i1<i2 then richedit1.SelStart:=i1
else richedit1.SelStart:=i2;
while richedit1.SelStart>=0 do
begin
if i1<i2 then
begin
richedit1.SelStart :=richedit1.FindText(s2,0,richedit1.GetTextLen,[stMatchCase]);
richedit1.SelLength:=3;
richedit1.seltext:='';
richedit1.SelLength := richedit1.GetTextLen; // select the word
richedit1.SelAttributes.color:=clBlue;
richedit1.SelLength:=0; // de-select the word
i1 :=richedit1.FindText(s2,0,richedit1.GetTextLen,[stMatchCase]);
end
else
begin
richedit1.SelStart :=richedit1.FindText(s3,0,richedit1.GetTextLen,[stMatchCase]);
richedit1.SelLength:=3;
richedit1.seltext:='';
richedit1.SelLength := richedit1.GetTextLen; // select the word
richedit1.SelAttributes.color:=clRed;
richedit1.SelLength:=0; // de-select the word
i2 :=richedit1.FindText(s3,0,richedit1.GetTextLen,[stMatchCase]);
end;
if i1<i2 then richedit1.SelStart:=i1
else richedit1.SelStart:=i2;
if richedit1.SelStart= richedit1.GetTextLen then break;
end;
end;
 
不奇怪
i1 :=richedit1.FindText(s2,0,richedit1.GetTextLen,[stMatchCase]);
i2 :=richedit1.FindText(s3,0,richedit1.GetTextLen,[stMatchCase]);
if i1 < i2 then richedit1.SelStart:=i1
else richedit1.SelStart:=i2;
while richedit1.SelStart>=0 do
begin
if i1 < i2 then
begin
richedit1.SelStart :=richedit1.FindText(s2,0,richedit1.GetTextLen,[stMatchCase]);
richedit1.SelLength:=3;
richedit1.seltext:='';
richedit1.SelLength := richedit1.GetTextLen; // select the word
richedit1.SelAttributes.color:=clBlue;
richedit1.SelLength:=0; // de-select the word
i1 :=richedit1.FindText(s2,0,richedit1.GetTextLen,[stMatchCase]);
end
else
begin
richedit1.SelStart :=richedit1.FindText(s3,0,richedit1.GetTextLen,[stMatchCase]);
richedit1.SelLength:=3;
richedit1.seltext:='';
richedit1.SelLength := richedit1.GetTextLen; // select the word
richedit1.SelAttributes.color:=clRed;
richedit1.SelLength:=0; // de-select the word
i2 :=richedit1.FindText(s3,0,richedit1.GetTextLen,[stMatchCase]);
end;
if i1 < i2 then richedit1.SelStart:=i1
else richedit1.SelStart:=i2;
if richedit1.SelStart= richedit1.GetTextLen then break;
end;
end;
 
sorry 很长时间没有上
我放弃使用richedit了 :(
办法是对的,但是闪烁.
 
后退
顶部