-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtvdaodlg.pas
237 lines (194 loc) · 6.41 KB
/
tvdaodlg.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
unit tvdaodlg;
interface
function EnterAddr(var A: word): boolean;
function EnterRange(var A1, A2: word; Prompt: string): boolean;
function EnterLabel(var L: string; Prompt: string): boolean;
procedure NotImplemented;
{---------------------------------------------------------------------------}
implementation
uses Objects, Dialogs, App, FVConsts, Views, Drivers, Validate, MsgBox,
DAGood;
const
HexNumberChars: set of char = ['0'..'9','A'..'F','a'..'f'];
LabelChars: set of char = ['A'..'Z','a'..'z','0'..'9','_','.'];
AlphaChars: set of char = ['A'..'Z','a'..'z'];
type
PHex4InputLine = ^THex4InputLine;
THex4InputLine = object(TInputLine)
constructor Init(R: TRect);
function DataSize: dword; virtual;
procedure GetData(var Rec); virtual;
procedure SetData(var Rec); virtual;
end;
PTvDaoEnterAddrDialog = ^TTvDaoEnterAddrDialog;
TTvDaoEnterAddrDialog = object(TDialog)
Edit: PHex4InputLine;
constructor Init(R: TRect);
end;
PTvDaoEnterRangeDialog = ^TTvDaoEnterRangeDialog;
TTvDaoEnterRangeDialog = object(TDialog)
EditFrom,EditTo,EditLen: PHex4InputLine;
constructor Init(R: TRect; Prompt: string);
end;
TEnterRangeData = record
A1, A2, A3: word;
end;
PEnterLabelDialog = ^TEnterLabelDialog;
TEnterLabelDialog = object(TDialog)
Edit: PInputLine;
constructor Init(R: TRect; Prompt: string);
end;
PLabelValidator = ^TLabelValidator;
TLabelValidator = object(TValidator)
function IsValid(const S: string): boolean; virtual;
end;
{---------------------------------------------------------------------------}
function ParseHex4(S: string): word;
var Res: word; I: integer; C: char;
begin
Res := 0;
for I := 1 to Length(S) do begin
Res := Res shl 4;
C := S[I];
if (C >= '0') and (C <= '9') then Res := Res + (Ord(C) - 48)
else if (C >= 'A') and (C <= 'F') then Res := Res + Word(Ord(C) - 65 + 10)
else if (C >= 'a') and (C <= 'f') then Res := Res + Word(Ord(C) - 97 + 10);
end;
ParseHex4 := Res;
end;
{---------------------------------------------------------------------------}
constructor THex4InputLine.Init(R: TRect);
begin
inherited Init(R, 4);
end;
function THex4InputLine.DataSize: dword;
begin
DataSize := SizeOf(Word);
end;
procedure THex4InputLine.GetData(var Rec);
begin
word(Rec) := ParseHex4(Data^);
end;
procedure THex4InputLine.SetData(var Rec);
begin
Data^ := Hex4(word(Rec));
end;
{---------------------------------------------------------------------------}
constructor TTvDaoEnterAddrDialog.Init(R: TRect);
begin
inherited Init(R, 'Enter Address');
R.Assign(4, 5, 14, 7);
Insert(New(PButton, Init(R, '~O~K', cmOK, bfDefault)));
R.Assign(15, 5, 26, 7);
Insert(new(PButton, Init(R, '~C~ancel', cmCancel, bfNormal)));
R.Assign(15, 2, 22, 3);
Edit := New(PHex4InputLine, Init(R));
Insert(Edit);
R.Assign(3, 2, 12, 3);
Insert(New(PLabel, Init(R, '~A~ddress:', Edit)));
Edit^.SetValidator(New(PFilterValidator, Init(HexNumberChars)));
end;
{---------------------------------------------------------------------------}
constructor TTvDaoEnterRangeDialog.Init(R: TRect; Prompt: string);
begin
inherited Init(R, 'Enter Range');
R.Assign(4, 2, 25, 3);
Insert(New(PStaticText, Init(R, Prompt)));
R.Assign(4, 7, 14, 9);
Insert(New(PButton, Init(R, '~O~K', cmOK, bfDefault)));
R.Assign(15, 7, 26, 9);
Insert(new(PButton, Init(R, '~C~ancel', cmCancel, bfNormal)));
R.Assign(15, 3, 22, 4);
EditFrom := New(PHex4InputLine, Init(R));
Insert(EditFrom);
R.Assign(3, 3, 12, 4);
Insert(New(PLabel, Init(R, '~F~rom:', EditFrom)));
R.Assign(15, 4, 22, 5);
EditTo := New(PHex4InputLine, Init(R));
Insert(EditTo);
R.Assign(3, 4, 12, 5);
Insert(New(PLabel, Init(R, '~T~o:', EditTo)));
R.Assign(15, 5, 22, 6);
EditLen := New(PHex4InputLine, Init(R));
Insert(EditLen);
R.Assign(3, 5, 12, 6);
Insert(New(PLabel, Init(R, '~L~ength:', EditLen)));
EditFrom^.SetValidator(New(PFilterValidator, Init(HexNumberChars)));
EditTo^.SetValidator(New(PFilterValidator, Init(HexNumberChars)));
EditLen^.SetValidator(New(PFilterValidator, Init(HexNumberChars)));
end;
{---------------------------------------------------------------------------}
constructor TEnterLabelDialog.Init(R: TRect; Prompt: string);
begin
inherited Init(R, 'Enter Label');
R.Assign(4, 2, 25, 3);
Insert(New(PStaticText, Init(R, Prompt)));
R.Assign(4, 5, 14, 7);
Insert(New(PButton, Init(R, '~O~K', cmOK, bfDefault)));
R.Assign(15, 5, 26, 7);
Insert(new(PButton, Init(R, '~C~ancel', cmCancel, bfNormal)));
R.Assign(15, 3, 26, 4);
Edit := New(PInputLine, Init(R, 8));
Insert(Edit);
R.Assign(3, 3, 12, 4);
Insert(New(PLabel, Init(R, '~L~abel:', Edit)));
Edit^.SetValidator(New(PFilterValidator, Init(LabelChars)));
Edit^.SetValidator(New(PLabelValidator, Init()));
end;
function TLabelValidator.IsValid(const S: string): boolean;
begin
if Length(S) = 0 then IsValid := false
else if not (S[1] in AlphaChars) then IsValid := false
else IsValid := true;
end;
{---------------------------------------------------------------------------}
function EnterAddr(var A: word): boolean;
var D: PTvDaoEnterAddrDialog; R: TRect; Data: word; Res: word;
begin
Desktop^.GetExtent(R);
R.Assign(60, R.A.X + 1, 60 + 30, R.A.X + 9);
D := New(PTvDaoEnterAddrDialog, Init(R));
Data := A;
D^.SetData(Data);
Res := Desktop^.ExecView(D);
D^.GetData(Data);
Dispose(D, Done);
A := Data;
EnterAddr := Res = cmOK;
end;
function EnterRange(var A1, A2: word; Prompt: string): boolean;
var D: PTvDaoEnterRangeDialog; R: TRect; Data: TEnterRangeData; Res: word;
begin
Desktop^.GetExtent(R);
R.Assign(60, R.A.X + 1, 60 + 30, R.A.X + 11);
D := New(PTvDaoEnterRangeDialog, Init(R, Prompt));
Data.A1 := A1;
Data.A2 := A2;
Data.A3 := A2 - A1 + 1;
D^.SetData(Data);
Res := Desktop^.ExecView(D);
D^.GetData(Data);
Dispose(D, Done);
A1 := Data.A1;
A2 := Data.A2;
EnterRange := Res = cmOK;
end;
function EnterLabel(var L: string; Prompt: string): boolean;
var D: PEnterLabelDialog; R: TRect; Data: string; Res: word;
begin
Desktop^.GetExtent(R);
R.Assign(60, R.A.X + 1, 60 + 30, R.A.X + 9);
D := New(PEnterLabelDialog, Init(R, Prompt));
Data := L;
D^.SetData(Data);
Res := Desktop^.ExecView(D);
D^.GetData(Data);
Dispose(D, Done);
L := Data;
EnterLabel := Res = cmOK;
end;
procedure NotImplemented;
begin
MessageBox(#3'This function is not '#13#3'implemented yet. Sorry :(', nil, mfOKButton);
end;
end.