Mega Code Archive

 
Categories / Delphi / Examples
 

Getseltext

SELECTING TEXT IN A RICHEDIT COMPONENT var startPos, endPos: LongInt; begin {for TESTING purposes, let's first select the text in line two here...} {but don't forget the RichEdit's line indeces are zero-based...} {startPos := SendMessage(IdiomREdit.Handle, EM_LINEINDEX, 1, 0); endPos := SendMessage(IdiomREdit.Handle, EM_LINEINDEX, 2, 0); IdiomREdit.SelStart := startPos; IdiomREdit.SelLength := (endPos - startPos); IdiomREdit.SelAttributes.Style := [fsBold];} {OK that works, what's next?} end; YOU CAN COPY SELECTED TEXT TO THE CLIPBOARD, LIKE THIS: var selectionLength: LongInt; begin selectionLength := IdiomREdit.SelLength; if (selectionLength > 0) then begin IdiomREdit.CopyToClipboard; MnREForm.ClipboardToCursor; end AND YOU CAN COPY SELECTED TEXT INTO YOUR OWN STRING VARIABLE IF U WANT, LIKE THIS: var myPChar: PChar; myString: String; selectionLength: LongInt; begin selectionLength := IdiomREdit.SelLength; if (selectionLength > 0) then begin IdiomREdit.SetFocus; {add room for null character in our PChar varaiable...} {Inc(selectionLength); GetMem(myPChar, selectionLength); IdiomREdit.GetSelTextBuf(myPChar, selectionLength); myString := String(myPChar); FreeMem(myPChar, selectionLength); } IdiomREdit.CopyToClipboard; MnREForm.ClipboardToCursor; end