var
gStart, gLength, gCol: Integer;
procedure SetRichEdit(aRichEdit: TRichEdit);
var
fRow, fCol: Integer;
fStart, fLength, tStart: Integer;
begin
fRow := aRichEdit.CaretPos.X;
fCol := aRichEdit.CaretPos.Y;
if gCol = fCol then Exit;
if aRichEdit.SelLength > then Exit;
tStart := aRichEdit.SelStart;
fStart := tStart - fRow;
fLength := aRichEdit.Lines[fCol].Length;
aRichEdit.Lines.BeginUpdate;
if fLength > then
begin
aRichEdit.SelStart := fStart;
aRichEdit.SelLength := fLength;
aRichEdit.SelAttributes.Color := clRed;
end;
if gLength > then
begin
aRichEdit.SelStart := gStart;
aRichEdit.SelLength := gLength;
// aRichEdit.SelectAll;
aRichEdit.SelAttributes.Color := clBlack;
end;
aRichEdit.SelStart := tStart;
aRichEdit.SelLength := ;
aRichEdit.Lines.EndUpdate;
gStart := fStart;
gLength := fLength;
gCol := fCol;
end;
procedure TForm1.RichEdit1Click(Sender: TObject);
begin
SetRichEdit(TRichEdit(Sender));
end;
procedure TForm1.RichEdit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key in [..] then SetRichEdit(TRichEdit(Sender));
end;