unit Unit3;

interface

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

type
  TForm3 = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    TrackBar1: TTrackBar;
    StaticText1: TStaticText;
    Pan3: TPanel;
    Label1: TLabel;
    Bevel1: TBevel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Panel2: TPanel;
    Image1: TImage;
    Panel3: TPanel;
    Pan2: TPanel;
    Pan4: TPanel;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure TrackBar1Change(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.BitBtn1Click(Sender: TObject);
var
  prefINI: TINIFile;
  i: integer;
begin
  prefINI := TINIFile.Create(ExtractFilePath(Application.EXEName) + 'preferences.ini');
  if TrackBar1.Position <> prefINI.ReadInteger('Players', 'Players', 4) then
  begin
    if MessageDlg('Wil je het speel herstarten?',    mtConfirmation, [mbYes, mbCancel],0) = mrYes then
    begin
      prefINI.WriteInteger('Players', 'Players', TrackBar1.Position);
      for i:=1 to 4 do
      prefINI.WriteString('Playernames', 'name'+IntToStr(i), (FindComponent('Edit'+IntToStr(i)) as TEdit).Text);
      prefINI.Free;
//      BitBtn1.ModalResult := mrRetry;
      form3.hide;
    end;
  end
  else
  begin
  for i:=1 to 4 do
  prefINI.WriteString('Playernames', 'name'+IntToStr(i), (FindComponent('Edit'+IntToStr(i)) as TEdit).Text);
  prefINI.Free;
//  BitBtn1.ModalResult := mrOk;
  form3.hide;
  end;
end;

procedure TForm3.BitBtn2Click(Sender: TObject);
begin
  form3.hide;
end;

procedure TForm3.TrackBar1Change(Sender: TObject);
var
  prefINI: TINIFile;
  i: integer;
begin
  prefINI := TINIFile.Create(ExtractFilePath(Application.EXEName) + 'preferences.ini');
if TrackBar1.Position = prefINI.ReadInteger('Players', 'Players', 4) then
  BitBtn1.ModalResult := mrOk
  else BitBtn1.ModalResult := mrRetry;
case TrackBar1.Position of
2 : begin
    Pan2.BevelInner := bvRaised;
    Pan3.BevelInner := bvLowered;
    Pan4.BevelInner := bvLowered;
    end;
3 : begin
    Pan2.BevelInner := bvLowered;
    Pan3.BevelInner := bvRaised;
    Pan4.BevelInner := bvLowered;
    end;
4 : begin
    Pan2.BevelInner := bvLowered;
    Pan3.BevelInner := bvLowered;
    Pan4.BevelInner := bvRaised;
    end;
  end;
end;



procedure TForm3.FormShow(Sender: TObject);
var
prefINI: TINIFile;
i: integer;
begin
  prefINI := TINIFile.Create(ExtractFilePath(Application.EXEName) + 'preferences.ini');
  TrackBar1.Position := prefINI.ReadInteger('Players', 'Players', 4);
  for i:=1 to 4 do
  (FindComponent('Edit'+IntToStr(i)) as TEdit).Text := prefINI.ReadString('Playernames', 'name'+IntToStr(i), 'Speler '+IntToStr(i));
case TrackBar1.Position of
2 : begin
    Pan2.BevelInner := bvRaised;
    Pan3.BevelInner := bvLowered;
    Pan4.BevelInner := bvLowered;
    end;
3 : begin
    Pan2.BevelInner := bvLowered;
    Pan3.BevelInner := bvRaised;
    Pan4.BevelInner := bvLowered;
    end;
4 : begin
    Pan2.BevelInner := bvLowered;
    Pan3.BevelInner := bvLowered;
    Pan4.BevelInner := bvRaised;
    end;
  end;
  prefINI.Free;
end;

end.
