ans:= RichEdit1.Text
for i:=1 to Length(ans) do
begin
RichEdit1.SelStart := i-1;
RichEdit1.SelLength:= 1;
if ans[i] = correct[i] then
RichEdit1.SelAttributes.Color := clRed
else
RichEdit1.SelAttributes.Color := clBlue;
If the letter in ans
matches the letter in the same position as the letter in correct
string, it is colored red otherwise, it is blue.
My problem is when I type again the whole RichEdit1 text is colored as the same as the first letter (if the first letter of RichEdit1
is blue then the whole text becomes blue).
By the way, this is not the the actual code I just simplified it because there are mutiple TRichEdits.
The TRichEdits are read-only and I assign the letters by something like RichEdit1.Text := RichEdit1.Text+Key;
(doing this because it's a multiple keyboard program and I need to separate user inputs)
Is this the correct behavior? How can I stop my color changes from overriding the default color?
update: Solved it... in a sloppy way (applying the default color whenever someone types), but I'm keeping this open in case someone comes up with a better solution.