OnSelectionChange (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example requires a TStatusBar and a TRichEdit. The code within the form's OnCreate sizes the Rich Edit and sets the OnSelectionChange event to be handled by RichEdit1SelectionChange. Note: You can also paste the code directly into the OnSelectionChange event handler. As you type in the Rich Edit control, the current character location where the selection begins and ends displays in the status bar control.

Code

procedure TForm1.RichEdit1SelectionChange(Sender: TObject);
begin
  with RichEdit1 do
    begin
    StatusBar1.SimpleText := '  Selection Start: ' + IntToStr(SelStart) +
      '  Selection End: ' + IntToStr(SelStart + SelLength);
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
const
  Path = 'OVERVIEW.RTF';
begin
  with RichEdit1 do
  begin
    Lines.LoadFromFile(Path);
    Align := alClient;
    OnSelectionChange := RichEdit1SelectionChange;
  end;
  StatusBar1.SimplePanel := True;
end;

Uses