unit Unit2;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
  INIFiles;

type

  { TForm2 }

  TForm2 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    CheckBox1: TCheckBox;
    Edit1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Panel1: TPanel;
    Panel2: TPanel;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    RadioButton5: TRadioButton;
    SelectDirectoryDialog1: TSelectDirectoryDialog;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure CheckBox1Change(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure RadioButton1Change(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure rbshow2();
  private

  public

  end;

var
  Form2: TForm2;

implementation
uses  Unit1;

{$R *.lfm}

{ TForm2 }

procedure TForm2.Button1Click(Sender: TObject);
begin
  Close();
end;

procedure TForm2.rbshow2();
begin
     if (Unit1.rb_cp866 = 1) then begin Form2.RadioButton3.Checked:=true; end;
     if (Unit1.rb_cp866 = 0) then begin Form2.RadioButton3.Checked:=false;  end;

     if (Unit1.rb_cp1251 = 1) then begin Form2.RadioButton4.Checked:=true;  end;
     if (Unit1.rb_cp1251 = 0) then begin Form2.RadioButton4.Checked:=false; end;

     if (Unit1.rb_utf8 = 1) then begin Form2.RadioButton5.Checked:=true;  end;
     if (Unit1.rb_utf8 = 0) then begin Form2.RadioButton5.Checked:=false;  end;
end;



procedure TForm2.Button2Click(Sender: TObject);
begin
  if SelectDirectoryDialog1.Execute then
  begin
    Form2.Edit1.Text:=SelectDirectoryDialog1.FileName;
    fpc_path:= Form2.Edit1.Text;
    RadioButton1.Checked:=false;
    RadioButton2.Checked:=true;
  end;

end;

procedure TForm2.Button3Click(Sender: TObject);
begin
  Inif := TINIFile.Create(ExtractFileDir(pr_path) + st_p + 'fpc.ini');
  Inif.WriteString('System', 'fpc_path', Form2.Edit1.Text);
  if CheckBox1.Checked then Inif.WriteString('System', 'pgui', '-WG')
   else Inif.WriteString('System', 'pgui', '');
  Inif.Free;
end;

procedure TForm2.CheckBox1Change(Sender: TObject);
begin
  if CheckBox1.Checked then Unit1.pgui:='-WG'
 else Unit1.pgui:=''
end;

procedure TForm2.FormActivate(Sender: TObject);
begin
  rbshow2();
end;


procedure TForm2.FormCreate(Sender: TObject);
begin
     Form2.Edit1.Text:=fpc_path;
     if fpc_path = '' then Form2.RadioButton1.Checked:=true else Form2.RadioButton1.Checked:=false;
     if fpc_path <> '' then Form2.RadioButton2.Checked:=true else Form2.RadioButton2.Checked:=false;
     if Unit1.pgui = '' then Form2.CheckBox1.Checked:=false;
     if Unit1.pgui = '-WG' then Form2.CheckBox1.Checked:=true;
end;

procedure TForm2.RadioButton1Change(Sender: TObject);
begin

end;

procedure TForm2.RadioButton1Click(Sender: TObject);
begin
     fpc_path := '';
     Form2.Edit1.Text:=fpc_path;
end;

procedure TForm2.RadioButton2Click(Sender: TObject);
begin
     fpc_path := Form2.Edit1.Text;
end;

end.

