-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfOptions.pas
136 lines (109 loc) · 2.7 KB
/
fOptions.pas
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
unit fOptions;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TfrmOptions = class(TForm)
Label1: TLabel;
OpenDialog1: TOpenDialog;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Edit1Exit(Sender: TObject);
private
function ReadApath: String;
procedure WriteAPath(const Value: String);
{ Private declarations }
public
{ Public declarations }
DirName:String;
fArduinoPath:String;
procedure chkArduinoPathValid;
Procedure ReadOptions;
Procedure WriteOptions;
property Arduinopath:String read ReadApath write WriteAPath;
end;
var
frmOptions: TfrmOptions;
implementation
uses iniFiles;
{$R *.dfm}
{ TForm1 }
procedure TfrmOptions.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Begin
ArduinoPath:= extractfilepath(opendialog1.FileName);
End;
end;
procedure TfrmOptions.chkArduinoPathValid;
var fn:string;
begin
fn:=edit1.Text+'\arduino.exe';
if not fileexists(fn) then raise Exception.Create('Äåí õðÜñ÷åé ôï Arduino.exe óå áõôü ôïí êáôÜëïãï.');
end;
procedure TfrmOptions.Edit1Exit(Sender: TObject);
begin
try
chkArduinoPathValid;
ArduinoPath:=edit1.Text;
except
on e:exception do
Begin
ShowMessage(e.Message);
edit1.Text:=arduinoPath;
End;
end;
end;
procedure TfrmOptions.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if modalresult=mrOk then
try
chkArduinoPathValid;
ArduinoPath:=edit1.Text;
Writeoptions;
except
on e:exception do
Begin
ShowMessage(e.Message);
edit1.Text:=arduinoPath;
Action:=caNone;
End;
end;
end;
procedure TfrmOptions.FormShow(Sender: TObject);
begin
dirname:= extractfilepath(Application.ExeName);
OpenDialog1.InitialDir:=dirname;
ReadOptions;
end;
function TfrmOptions.ReadApath: String;
begin
Result:=fArduinoPath;
end;
procedure TfrmOptions.ReadOptions;
var IniFile:TInifile;
begin
IniFile:=TInifile.Create(DirName+'\Options.ini');
ArduinoPath:=IniFile.ReadString('Arduino','Path',extractfilepath(Application.ExeName)+'Arduino');
IniFile.Free;
opendialog1.InitialDir:=ArduinoPath;
end;
procedure TfrmOptions.WriteAPath(const Value: String);
begin
fArduinoPath:=Value;
edit1.Text:=fArduinopath;
end;
procedure TfrmOptions.WriteOptions;
var IniFile:TInifile;
begin
IniFile:=TInifile.Create(DirName+'\Options.ini');
IniFile.WriteString('Arduino','Path',ArduinoPath);
IniFile.Free;
end;
end.