unit UnitAddLink;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TFormAddLink = class(TForm)
    Panel0: TPanel;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    Label1: TLabel;
    EditHtml: TEdit;
    Label2: TLabel;
    EditFile: TEdit;
    Button1: TButton;
    Label3: TLabel;
    EditNStr: TEdit;
    Panel1: TPanel;
    Button2: TButton;
    Button3: TButton;
    Label4: TLabel;
    EditHtml2: TEdit;
    OpenDialog1: TOpenDialog;
    procedure RadioButton2Click(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure EditFileChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormAddLink: TFormAddLink;

implementation

{$R *.dfm}

procedure TFormAddLink.RadioButton2Click(Sender: TObject);
begin
  // Ссылка на файл PDF в папке System
  if RadioButton1.Checked then
  begin
    EditHtml.Color := clWhite;
    EditHtml.Enabled := true;
    EditFile.Color := clSilver;
    EditNStr.Color := clSilver;
    EditFile.Enabled := false;
    EditNStr.Enabled := false;
    Button1.Enabled := false;
  end
  else
  begin
    EditHtml.Color := clSilver;
    EditHtml.Enabled := false;
    EditFile.Color := clWhite;
    EditNStr.Color := clWhite;
    EditFile.Enabled := true;
    EditNStr.Enabled := true;
    Button1.Enabled := true;
  end;




end;

procedure TFormAddLink.RadioButton1Click(Sender: TObject);
begin
  // Гиперссылка
  if RadioButton1.Checked then
  begin
    EditHtml.Color := clWhite;
    EditHtml.Enabled := true;
    EditFile.Color := clSilver;
    EditNStr.Color := clSilver;
    EditFile.Enabled := false;
    EditNStr.Enabled := false;
    Button1.Enabled := false;
  end
  else
  begin
    EditHtml.Color := clSilver;
    EditHtml.Enabled := false;
    EditFile.Color := clWhite;
    EditNStr.Color := clWhite;
    EditFile.Enabled := true;
    EditNStr.Enabled := true;
    Button1.Enabled := true;
  end;

end;

procedure TFormAddLink.Button1Click(Sender: TObject);
begin
  // Выбрать файл
  OpenDialog1.InitialDir := ExtractFilePath( Application.ExeName ) + 'System';
  OpenDialog1.FileName := OpenDialog1.InitialDir + '\pdd.pdf';
  if OpenDialog1.Execute then
  begin
    EditFile.Text := ExtractFileName( OpenDialog1.FileName );
  end;
  
end;

procedure TFormAddLink.EditFileChange(Sender: TObject);
var
  l : string;
begin
  // при изменении меняем ссылку
  l := 'file:///' + Trim(EditFile.Text);
  if Trim(EditNStr.Text) <> '' then
  begin
    l := l + '#page=' + Trim(EditNStr.Text);
  end;

  EditHtml2.Text := l;
end;

procedure TFormAddLink.FormShow(Sender: TObject);
begin
  EditFileChange(self);
end;

end.
