RAD Studio VCL Reference
|
Specifies the selected portion of the edit control's text.
property SelText: string;
__property AnsiString SelText;
Read SelText to determine the value of the selected text. Set SelText to replace the selected text with a new string. If there is no selection, but the edit control has focus, set SelText to insert a new string into the text at the cursor.
C++ Examples:
/* This example copies selected text from one text edit to another. This example requires two text edits and two buttons. */ Char *Buffer; #include <memory> //for STL auto_ptr class void __fastcall TForm1::Button1Click(TObject *Sender) { int Size = Edit1->SelLength; //Get length of selected text in Edit1 Size++; //Add room for null character static std::auto_ptr<Char> _BufferCleaner(Buffer = new Char[Size]); Edit1->GetSelTextBuf(Buffer, Size); //Puts Edit1->Text into Buffer Edit2->Text = Buffer; } //--------------------------------------------------------------------------- /* Note: the same thing could be accomplished more simply as follows: */ void __fastcall TForm1::Button2Click(TObject *Sender) { Edit2->Text = Edit1->SelText; }
Delphi Examples:
{ This example copies selected text from one text edit to another. This example requires two text edits and two buttons. } procedure TForm1.Button1Click(Sender: TObject); var Buffer: PChar; Size: Integer; begin Size := Edit1.SelLength; {Get length of 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 Pascal-style string} FreeMem(Buffer, Size);{Frees memory allocated to Buffer} end; { Note: the same thing could be accomplished more simply as follows: } procedure TForm1.Button2Click(Sender: TObject); begin Edit2.Text := Edit1.SelText; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|