unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, ExtCtrls, ComCtrls, StdCtrls, XPMan, Buttons;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    re: TRichEdit;
    StatusBar1: TStatusBar;
    ControlBar1: TControlBar;
    Panel1: TPanel;
    Panel2: TPanel;
    od: TOpenDialog;
    sd: TSaveDialog;
    N2: TMenuItem;
    N3: TMenuItem;
    txt1: TMenuItem;
    rtf1: TMenuItem;
    N4: TMenuItem;
    N5: TMenuItem;
    sb1: TSpeedButton;
    sb2: TSpeedButton;
    procedure N2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure sb1Click(Sender: TObject);
    procedure reSelectionChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
     sb: array[1..2] of TSpeedButton;

implementation

{$R *.dfm}

procedure TForm1.N2Click(Sender: TObject);
begin
  if od.Execute
    then re.Lines.LoadFromFile(od.FileName);
end;

procedure TForm1.FormCreate(Sender: TObject);
var dir: string;
begin
  getdir(0,dir);
  od.InitialDir:=dir;
  sb[1]:=sb1; sb[2]:=sb2;
end;

procedure TForm1.sb1Click(Sender: TObject);
var temp: TFontStyles;
begin
  with re.SelAttributes,sb[(Sender as TSpeedButton).Tag] do
  begin
  case (Sender as TSpeedButton).Tag of
    1: temp:=[fsBold];
    2: temp:=[fsItalic];
  end;
    if Down{=true}
      then Style:=Style+temp
      else Style:=Style-temp;
  end;    
end;

procedure TForm1.reSelectionChange(Sender: TObject);
begin
  if fsBold in re.SelAttributes.Style
    then sb1.Down:=true
    else sb1.Down:=false;
end;

end.

//(fsBold, fsItalic, fsUnderline, fsStrikeOut);
