简单问题,但是请高手入内:有关RichEdit (30分)

  • 主题发起人 主题发起人 base7
  • 开始时间 开始时间
B

base7

Unregistered / Unconfirmed
GUEST, unregistred user!
有这样一个字符串:
mstr := 'ABCD'#0'abcd'
如何使用这个过程:
RichEdit1.Lines.Add(mstr);??
使得在RichEdit1最后一行加上'ABCDabcd'这样一个字串?
 
with rih_Words do
begin
if Length(Text)<>0 then
Lines.Add('');
Selattributes.Style := SelAttributes.Style + [fsBold] + [fsItalic];
SelStart := Length(Text);
SelLength := 0;
SelAttributes.Color := clBlue;
SelText := SendMan;

Selattributes.Style := SelAttributes.Style - [fsItalic];
SelStart := Length(Text);
SelLength := 0;
SelAttributes.Color := rgb(255,0,128);
SelText := '对';

Selattributes.Style := SelAttributes.Style + [fsBold] + [fsItalic];
SelStart := Length(Text);
SelLength := 0;
SelAttributes.Color := clBlue;
SelText := ReceiveMan;

Selattributes.Style := SelAttributes.Style - [fsItalic];
SelStart := Length(Text);
SelLength := 0;
SelAttributes.Color := rgb(255,0,128);
SelText := '说:';

Selattributes.Style := SelAttributes.Style - [fsItalic]-[fsBold];
SelStart := Length(Text);
SelLength := 0;
SelAttributes.Color := clBlack;
SelText := Word;

SelLength := 0;
SelStart := GetTextLen;
Perform(EM_SCROLLCARET,0,0);
end;
 
hehe, yeath:
这是从聊天室里的程序里考出来的吧,用来显示颜色字体.
可是,请你执行一下:
richedit1.lines.add('ABCD'#0'abcd');
这行代码,就知道我问这个问题的原因了
 
不是,是我自己写的聊天程序里的,我帮你看看。
 
为什么要加#0????
文本遇到到#0就会认为结束了。
不信你试试
showmessage('ABCD'#0'abcd');
 
我也出现过这个问题,也想请教一下别人
 
var
k,l:string;
i:integer;
begin

k:=('ABCD'#0'abcd');
l:='';
for i:=1 to Length(k) do
begin
if k<>#0 then
l:=l+k;
end;
richedit1.Lines.Add(l);
end;
 
wr960204同志的方法比较好了。其他的方法不是很好了。你试试的了
 
wr960204:
因为这个字符串是通过网络传递过来的,所以中间有#0这样的字符
你写的代码能解决问题吗?我试试,不过..没有更好的解决方法吗?
因为#0只是我举的一个例子,其中还可能有#$A等多种字符
 
那种字符是没关系的。
 
to yeath:
可是,系统报错啊,怎么会没关系?
memo里倒是真的没关系,不知为什么
 
执行wr960204的过程报错?
 
自己做个过程把 #0 删除:

procedure RemoveNull(var s:string);
var
i:integer;
ss:string;
begin
ss:='';
for i:=1 to length(s) do
if s<>#0 then ss:=ss+s;
S:=SS;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
mstr:string;
begin
mstr := 'ABCD'#0'abcd' ;
RemoveNull(mstr);
RichEdit1.Lines.Add(mstr);
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
k,l:string;
i:integer;
begin
k:=('ABCD'#0#$a'abcd');
l:='';
for i:=1 to Length(k) do
begin
if k<>#0 then
l:=l+k;
end;
richedit1.Lines.Add(l);
end;
这样没问题啊
 
多人接受答案了。
 
后退
顶部