RichEdit.SelStart - 1。您是初学么?服了。
给你写了个例程,用来改变当前光标前一个字符的颜色(可以辨别汉字和ASCII):
procedure TForm1.Button1Click(Sender: TObject);
var
sel, len: Integer;
begin
sel := RichEdit1.SelStart;
len := RichEdit1.SelLength;
if len = 0 then
begin
with RichEdit1 do
begin
if (CaretPos.X = 0) and (CaretPos.Y > 0) then
SelStart := SelStart - 2;
if (CaretPos.X > 1) and IsDBCSLeadByte(Byte(Lines[CaretPos.Y][CaretPos.X - 1])) then
begin
SelStart := SelStart - 2;
SelLength := 2;
end
else if CaretPos.X > 0 then
begin
SelStart := SelStart - 1;
SelLength := 1;
end;
end;
end;
RichEdit1.SelAttributes.Color := clRed;
if len = 0 then
begin
RichEdit1.SelStart := sel;
RichEdit1.SelLength := len;
end;
end;