so what we need to do is select the word 'unit' in the richedit control, and set its attributes. we do this by setting selstart to the position of 'unit' in the richedit control, and sellength to the length of the word 'unit'. and since 'unit' is at the beginning of the current line - thats position is beginselstart (which i conveninently have stored in myselstart - you'll see why). lets replace the "pseudo" comment code with the following:
myre.selstart := myselstart;
myre.sellength := length(mytokenstr);
myre.selattributes.assign(pascon.fparsefont[mytokenstate]);end;
but remember we are in a loop - when we go around again we'll have the next token in the line, and the variables will look like this:
|
variables |
01234567901234567890 |
| lines.strings[r0] | unit unit1; |
| mypbuff | unit unit1; |
| mytokenstate | tsspace |
| mytokenstr | (space character) |
| myrun | unit1; |
but (space character) isn't at beginselstart (#0) in the richedit control. its further along (at position #4). which just happens to be beginselstart + length('unit'). we need to update myselstart after we process the preceeding token, but before we go around the loop again:
myselstart := myselstart + length(mytokenstr);
end;
okay - this is where we are standing at the moment:
| procedure tform1.richedit1change(sender: tobject);
var
begin
end; |