SelText (Delphi)
From RAD Studio XE2 Code Examples
Language:
Description
This example copies selected text from one text edit to another. This example requires two text edits and two buttons.
Code
procedure TForm1.Button1Click(Sender: TObject); var Buffer: PChar; Size: Integer; begin Size := Edit1.SelLength; { Get the length of the selected text in Edit1. } Inc(Size); { Add room for null character. } GetMem(Buffer, Size); { Creates Buffer dynamic variable. } Edit1.GetSelTextBuf(Buffer,Size); { Puts Edit1.Text into Buffer. } Edit2.Text := StrPas(Buffer);{ Converts Buffer into a Pascal-style string. } FreeMem(Buffer, Size);{Frees the memory allocated to Buffer. } end; { Note: The same effect can be obtained, more simply, as follows: procedure TForm1.Button2Click(Sender: TObject); begin Edit2.Text := Edit1.SelText; end;
Uses
- Vcl.StdCtrls.TCustomEdit.GetSelTextBuf ( fr | de | ja )
- Vcl.StdCtrls.TCustomEdit.SelText ( fr | de | ja )