procedure TForm1.RichEditMsgAdd(str:string;colorType:integer);
var
i:integer;
begin
if colorType=1 then
begin
RichEditMsg.SelAttributes.Color := clRed;
RichEditMsg.Lines.Add(TimeToStr(time)+'->'+str); SendMessage(RichEditMsg.Handle, WM_VSCROLL, gDWORD,gTagS.fMask);
end
else
begin
RichEditMsg.SelAttributes.Color := clBlack;
RichEditMsg.Lines.Add(TimeToStr(time)+'->'+str);
SendMessage(RichEditMsg.Handle, WM_VSCROLL, gDWORD,gTagS.fMask);
end; if RichEditMsg.Lines.Count>100 then
begin
try
for i:=0 to RichEditMsg.Lines.Count-101 do
begin
RichEditMsg.Lines.Delete(0);
end;
except
end;
end;上面的代码意思是,保持lines都在100行,大于的就删除最前面的多余的行,但执行后,前面比如某些行是红色的,但执行Lines.Delete后,前面某些红色行都变成了黑色,既全部都黑色了,我想Lines.Delete后,前面的行原来是什么颜色就是什么颜色。
或者有必要Lines.Delete吗,RichEdit当最大行大于多少时会自动删除首行吗?我怕的是RichEdit无限添加行后,那没个限度,或限度的处理,那不是资源越占越多,所以我才大于100行就删。
当然,绝对不能使用RichEditMsg.Lines.clear函数,这样很不好,什么都清除了。
高手帮帮忙吧。
var
i:integer;
begin
if colorType=1 then
begin
RichEditMsg.SelAttributes.Color := clRed;
RichEditMsg.Lines.Add(TimeToStr(time)+'->'+str); SendMessage(RichEditMsg.Handle, WM_VSCROLL, gDWORD,gTagS.fMask);
end
else
begin
RichEditMsg.SelAttributes.Color := clBlack;
RichEditMsg.Lines.Add(TimeToStr(time)+'->'+str);
SendMessage(RichEditMsg.Handle, WM_VSCROLL, gDWORD,gTagS.fMask);
end; if RichEditMsg.Lines.Count>100 then
begin
try
for i:=0 to RichEditMsg.Lines.Count-101 do
begin
RichEditMsg.Lines.Delete(0);
end;
except
end;
end;上面的代码意思是,保持lines都在100行,大于的就删除最前面的多余的行,但执行后,前面比如某些行是红色的,但执行Lines.Delete后,前面某些红色行都变成了黑色,既全部都黑色了,我想Lines.Delete后,前面的行原来是什么颜色就是什么颜色。
或者有必要Lines.Delete吗,RichEdit当最大行大于多少时会自动删除首行吗?我怕的是RichEdit无限添加行后,那没个限度,或限度的处理,那不是资源越占越多,所以我才大于100行就删。
当然,绝对不能使用RichEditMsg.Lines.clear函数,这样很不好,什么都清除了。
高手帮帮忙吧。
用数组保存颜色 太麻烦了,影响速度。
RichEdit1.Lines.Delete(0);
后颜色都变黑色了,红色就显示不了了,我上面描述的问题没解决呀。
用个苯方法行不行,
删到100行后
RichEditMsg.SelectAll;
RichEditMsg.CopyToClipboard;
RichEditMsg.Clear;
RichEditMsg.PasteFromClipboard;
RichEditMsg.Lines.Delete(RichEditMsg.Lines.Count-1);
现在贴出来给大家分享:
procedure TForm1.RichEditMsgAdd(str:string;colorType:integer);
var
i:integer;
begin
while RichEditMsg.Lines.Count>=6 do
RichEditMsg.Lines.Delete(0); RichEditMsg.SelectAll;
RichEditMsg.CopyToClipboard;
RichEditMsg.Clear;
RichEditMsg.PasteFromClipboard;
RichEditMsg.Lines.Delete(RichEditMsg.Lines.Count-1); if colorType=1 then
begin
RichEditMsg.SelAttributes.Color := clRed;
RichEditMsg.Lines.Add(TimeToStr(time)+'->'+str); //SendMessage(RichEditMsg.Handle, WM_VSCROLL, gDWORD,gTagS.fMask);
end
else
begin
RichEditMsg.SelAttributes.Color := clBlack;
RichEditMsg.Lines.Add(TimeToStr(time)+'->'+str);
//SendMessage(RichEditMsg.Handle, WM_VSCROLL, gDWORD,gTagS.fMask);
end; {if RichEditMsg.Lines.Count>5 then
begin
try
for i:=0 to RichEditMsg.Lines.Count-6 do
begin
RichEditMsg.Lines.Delete(0);
end;
except
end;
end; }end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RichEdit1.Lines.Delete(0);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
RichEdit1.Lines.LoadFromFile('d:\1.rtf');
end;肯定是你在删除的时候别的地方同时改动了文件了,在删除之前停止一切写入,删完之后再放开
我用
RichEditMsg.SelectAll;
RichEditMsg.CopyToClipboard;
RichEditMsg.Clear;
RichEditMsg.PasteFromClipboard;
RichEditMsg.Lines.Delete(RichEditMsg.Lines.Count-1);
Clear以后PasterFromClipboard没有用,是不是有什么地方有什么属性要求?