unit MainForm;
{$mode delphi}
{$codepage UTF8}
interface
uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, EditBtn, ComCtrls, Spin,
     windows, SimplyJSON;
type
  { TMainFrm }
  TMainFrm = class(TForm)
    WriteBtn: TButton;
    ExitBtn: TButton;
    bValueEd: TComboBox;
    iValueEd: TSpinEdit;
    sValueEd: TEdit;
    JSONFileNameEd: TFileNameEdit;
    JSONFileNameEdLbl: TLabel;
    KeyEdt: TLabeledEdit;
    BooleanSht: TTabSheet;
    ValueEdLbl: TLabel;
    StringSht: TTabSheet;
    IntegerSht: TTabSheet;
    ValuePages: TPageControl;
    RecTypeEd: TRadioGroup;
    procedure ExitBtnClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure RecTypeEdSelectionChanged(Sender: TObject);
    procedure WriteBtnClick(Sender: TObject);
  private
  public
  end;
var
  MainFrm: TMainFrm;
implementation
{$R *.lfm}
{ TMainFrm }
procedure TMainFrm.ExitBtnClick(Sender: TObject);
begin
Application.Terminate;
end;
procedure TMainFrm.FormCreate(Sender: TObject);
begin
RecTypeEd.ItemIndex:= 0;
ValuePages.ActivePage:= StringSht;
end;
procedure TMainFrm.RecTypeEdSelectionChanged(Sender: TObject);
begin
case RecTypeEd.ItemIndex of
 0: ValuePages.ActivePage:= StringSht;
 1: ValuePages.ActivePage:= IntegerSht;
 2: ValuePages.ActivePage:= BooleanSht;
 end;
end;
procedure TMainFrm.WriteBtnClick(Sender: TObject);
begin
if Trim(JSONFileNameEd.Text) = '' then
 begin
 Application.MessageBox(PChar('Поле "Имя файла" не заполнено!'), PChar('Ошибка!'), MB_ICONERROR);
 Abort;
 end;
if Trim(KeyEdt.Text) = '' then
 begin
 Application.MessageBox(PChar('Поле "Ключ" не заполнено!'), PChar('Ошибка!'), MB_ICONERROR);
 Abort;
 end;
case RecTypeEd.ItemIndex of
 0: JSWriteString(KeyEdt.Text, sValueEd.Text, JSONFileNameEd.Text);
 1: JSWriteInteger(KeyEdt.Text, iValueEd.Value, JSONFileNameEd.Text);
 2: JSWriteBoolean(KeyEdt.Text, (bValueEd.ItemIndex = 0), JSONFileNameEd.Text);
 end;
Application.MessageBox(PChar('Выполнено!'), PChar('Информация'), MB_ICONASTERISK);
end;
end.
