RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomEdit.SelectAll Method

Selects all text in the edit control.

Pascal
procedure SelectAll;
C++
__fastcall SelectAll();

Use SelectAll to select all text in the edit control. To select only part of the text, use the SelStart and SelLength properties.  

C++ Examples: 

 

/*
This example uses an edit box, a rich edit control, and a
button on a form. When the user clicks the button, text is
cut from the rich edit control and pasted into the edit box.
Note that only the text is pasted. If the rich edit control
includes any formatting information that is not pasted into
the edit control.  If the destination where a rich edit
control, the formatting information would be copied as well.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  // ensure that all the text is cut, not just the current selection
  RichEdit1->SelectAll();  
  RichEdit1->CutToClipboard();
  Edit1->Clear();
  Edit1->PasteFromClipboard();
  RichEdit1->SetFocus();
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  const AnsiString Path = "../overview.rtf";
  RichEdit1->PlainText = False;
  RichEdit1->Lines->LoadFromFile(Path);
  RichEdit1->ScrollBars = ssVertical;
}

 

Delphi Examples: 

{
This example uses an edit box, a rich edit control, and a
button on a form. When the user clicks the button, text is
cut from the rich edit control and pasted into the edit box.
Note that only the text is pasted. If the rich edit control
includes any formatting information that is not pasted into
the edit control.  If the destination where a rich edit
control, the formatting information would be copied as well.
} 
procedure TForm1.Button1Click(Sender: TObject);
begin
  RichEdit1.SelectAll;  { ensure that all the text is cut, not just the current selection }
  RichEdit1.CutToClipboard;
  Edit1.Clear;
  Edit1.PasteFromClipboard;
  RichEdit1.SetFocus;
end;

procedure TForm1.FormCreate(Sender: TObject);
const
  Path = 'OverView.RTF';
begin
  RichEdit1.PlainText := False;
  RichEdit1.Lines.LoadFromFile(Path);
  RichEdit1.ScrollBars := ssVertical;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!