SelText (C++)

From RAD Studio Code Examples
Jump to: navigation, search


This example copies selected text from one text edit to another. The example requires two text edits and two buttons.

Char *Buffer;


void __fastcall TForm1::Button1Click(TObject *Sender)
  int Size = Edit1->SelLength; //Get the length of the selected text in Edit1.
  Size++;                      //Add room for null character.
  Char *Buffer = new Char[Size];  //Creates Buffer dynamic variable
  Edit1->GetSelTextBuf(Buffer,Size); //Puts Edit1->Text into Buffer
  Edit2->Text = Buffer;
  delete [] Buffer;
Note: The same thing could be accomplished easier as follows:
void __fastcall TForm1::Button2Click(TObject *Sender)
  Edit2->Text = Edit1->SelText;