Author: Jonas Bilinkevicius
I need to be able to (preferrably dynamically as the user is typing text) to
specify a line break of say 70 characters so that the cursor will go to a new line
upon reaching the 70 character limit. Actually it would be best to break on the
last word boundary but even a break at 70 characters would give me a start.
Answer:
I've had a play with this and the following is the best I could come up with
quickly. At least it may give you a start:
Set a Variable called Backpace : Boolean = False ;
1 2 procedure GetCurrentRC(re1: TRichedit; var row, col: LongInt);
3 begin4 {Get Current Row and Column Values for Richedit Control}5 with re1 do6 begin7 Row := sendMessage(handle, EM_LINEFROMCHAR, Selstart, 0);
8 Col := selstart - sendmessage(handle, EM_LINEINDEX, row, 0);
9 end;
10 end;
11 12 procedure TForm1.re1SelectionChange(Sender: TObject);
13 var14 RTRow, RTCol: LongInt;
15 begin16 GetCurrentRC(re1, RTRow, RTCol);
17 if (rtCol = 70) and (not Backspace) then18 re1.Lines[rtRow] := Memo1.Lines[rtRow] + #13#10;
19 end;
20 21 procedure TForm1.Re1KeyPress(Sender: TObject; var Key: Char);
22 begin23 {If Backspacing we don't want it to jump down again}24 if key = #8 then25 backspace := True
26 else27 backspace := False;
28 end;
I think that's about right. You would have to search on the position of any space if you wanted to break on a word boundary.