OK, here is my attempt to do what I think you want to.
procedure TForm1.Button2Click(Sender: TObject);
var
BlockNo, PosInBlock : longint;
begin
BlockNo := kmemo1.Blocks.IndexToBlockIndex(KMemo1.RealSelStart, PosInBlock) + 2;
while BlockNo < Kmemo1.Blocks.Count do
if TKMemoTextBlock(KMemo1.Blocks.Items[BlockNo]).TextStyle.Font.Color = clRed then break
else BlockNo := BlockNo + 2;
if BlockNo < Kmemo1.Blocks.Count then begin
Kmemo1.SelStart := KMemo1.Blocks.BlockToIndex(KMemo1.Blocks.Items[BlockNo]);
Kmemo1.SelEnd := KMemo1.Blocks.BlockToIndex(KMemo1.Blocks.Items[BlockNo]);
Kmemo1.SetFocus;
end;
end;
Note that when you click the button you move the focus away from KMemo1, I wonder if that was what was causing your problem ? (Note I has assumed every line is one block long so can index by 2 and skip paragraph marker, I'm sure you can do better in a real life app)
Davo