为了我按照下面代码写,但是没有对相应文字选择呢?
with richedit do
  begin
    istart  :=Length(Text);
    Lines.Add ('今天你好')  ;
    iPos:=Length(Text);
    SelLength :=iPos-istart;
    SelAttributes.Color:=clRed ;
  end;
“今天你好”没有变成红色,这是为什么?

解决方案 »

  1.   


    SelStart  :=Length(Text);
        Lines.Add ('½ñÌìÄãºÃ')  ;
        iPos:=Length(Text);
        SelLength :=iPos-selstart;    SelAttributes.Color:=clRed ;
    这样子还是不行
      

  2.   

    添加一个richedit控件和一个button
    在button的click事件中写入下边的代码
    procedure TForm1.Button2Click(Sender: TObject);
    var
      ipos:integer;
    begin
      with richedit1 do
      begin
        Lines.Add ('今天你好')  ;
        iPos:=Length(Text);
        SelStart :=0;
        SelLength :=iPos;
        SelAttributes.Color:=clRed ;
      end;
      

  3.   

    这样的!先要清空richedit控件内容才行!如果不清空的话,先要自己设置一下开始位置!
    procedure TForm1.Button1Click(Sender: TObject);
    var
      ipos:integer;
    begin
      RichEdit1.Clear;
      with RichEdit1 do
      begin
        Lines.Add ('今天你好')  ;
        iPos:=Length(Text);
        SelStart :=0;
        SelLength :=iPos;
        SelAttributes.Color:=clRed ;
      end;
    end;
      

  4.   

    我就想在不清空的状态下,selstart如下设置还是不行 var
      ipos:integer;
    begin
      with REdit1 do
      begin
          SelStart := Length(Text);
        Lines.Add ('½ñÌìÄãºÃÂð')  ;
        iPos:=Length(Text);
        SelLength :=iPos-selstart;
        SelAttributes.Color:=clRed ;
      end;
    end;
      

  5.   

    那你设置一下起始位置就可以了呀!
    SelStart :=0; //把这个修改成你文字的起始位置
      

  6.   


    procedure TForm1.Button1Click(Sender: TObject);
    var
      ipos:integer;
    begin
      RichEdit1.Text :='RichEdit1';
      with RichEdit1 do
      begin
        Lines.Add ('今天你好')  ;
        iPos:=Length(Text);
        SelStart :=9;    //重要的是找到起始位置!
        SelLength :=iPos;
        SelAttributes.Color:=clRed;
      end;
    end;