aboutsummaryrefslogtreecommitdiff
path: root/Source/configureunit.pas
blob: 88dff73b5db727f5d075de2ed66587737d9be553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
unit configureunit;

interface

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

type
  Tconfigure = class(TForm)
    PageControl1: TPageControl;
    TSConnections: TTabSheet;
    Panel1: TPanel;
    ButtonOk: TButton;
    ButtonCancel: TButton;
    Label1: TLabel;
    EditPdHost: TEdit;
    Label2: TLabel;
    EditPdReceivePort: TEdit;
    Label3: TLabel;
    EditPdSendPort: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    EditFsPort: TEdit;
    CBEnableFSConns: TCheckBox;
    TSGeneral: TTabSheet;
    CBDockMain: TCheckBox;
    procedure ButtonCancelClick(Sender: TObject);
    procedure ButtonOkClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure Execute;
  end;

var
  configure: Tconfigure;

implementation

uses
  Registry,
  mainunit;

{$R *.DFM}

procedure Tconfigure.ButtonOkClick(Sender: TObject);
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CURRENT_USER;

  main.PdHost := EditPdHost.Text;
  main.PdReceivePort := StrToInt(EditPdReceivePort.Text);
  main.PdSendPort := StrToInt(EditPdSendPort.Text);
  main.FSPort := StrToInt(EditFsPort.Text);
  main.EnableFSConns := CBEnableFSConns.Checked;
  main.DockMain := CBDockMain.Checked;

  try
    if Reg.OpenKey('\Software\Framestein', True) then begin
      Reg.WriteString('PdHost', main.PdHost);
      Reg.WriteInteger('PDReceivePort', main.PDReceivePort);
      Reg.WriteInteger('PDSendPort', main.PDSendPort);
      Reg.WriteInteger('FSPort', main.FSPort);
      Reg.WriteBool('EnableFSConns', main.EnableFSConns);
      Reg.WriteBool('DockMain', main.DockMain);
    end;
  except
  end;

  Reg.CloseKey;
  Reg.Free;

  main.ss1.Active := False;
  main.ss1.Port := main.PDReceivePort;
  main.ss1.Active := True;

  main.csToPd.Active := False;
  main.csToPd.Host := main.PdHost;
  main.csToPd.Port := main.PdSendPort;
  main.csToPd.Active := True;

  main.ssfs.Active := False;
  main.ssfs.Port := main.FSPort;
  main.ssfs.Active := main.EnableFSConns;

  ModalResult := mrOk;
end;

procedure Tconfigure.ButtonCancelClick(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure Tconfigure.Execute;
begin
  // load values from main
  EditPdHost.Text := main.PdHost;
  if EditPdHost.Text='' then EditPdHost.Text:='localhost';
  EditPdReceivePort.Text := IntToStr(main.PdReceivePort);
  EditPdSendPort.Text := IntToStr(main.PdSendPort);
  EditFsPort.Text := IntToStr(main.FSPort);
  CBEnableFSConns.Checked := main.EnableFSConns;
  CBDockMain.Checked := main.DockMain;
  // show
  ShowModal;
end;

procedure Tconfigure.FormCreate(Sender: TObject);
begin
  if main.RunConfig then
    Execute;
end;

end.