-
Notifications
You must be signed in to change notification settings - Fork 1
/
TVUtil.pas
769 lines (676 loc) · 19.5 KB
/
TVUtil.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
unit TvUtil;
{&Use32+}
{#F ****************************************************}
{ }
{ TVutil unit }
{ }
{ Copyright (C) 11-16-92 James M. Clark }
{ }
{ General utilities for TurboVision applications }
{ Includes #simple_input_lines#. }
{ }
{#F ****************************************************}
interface
uses Objects, Dialogs;
function ExecDialog(P: PDialog; Data: Pointer): Word;
{#F ****************************************************}
{ }
{ Execute given PDialog with given Data. }
{ Data is unchanged if dialog is cancelled. }
{ }
{#F ****************************************************}
type
PTextArray = ^TTextArray;
TTextArray = array[byte] of String[10];
{ used by #TIndexedText# }
PIndexedText = ^TIndexedText;
TIndexedText = object(TStaticText)
{#F ****************************************************}
{ }
{ This status display object displays one name of }
{ a given array of names, given by an index of the }
{ array. The address of the array and index are }
{ specified when the object is initialized. }
{ }
{#F ****************************************************}
TextArray: PTextArray;
Index: ^word;
constructor Init(var Bounds: TRect;
var AText; {an array of string[10] names}
var AIndex: word {an index of the array}
);
procedure GetText(var S: string); virtual;
function DataSize: word; virtual;
end;
type
PNumReport = ^TNumReport;
TNumReport = object(TStaticText)
{#F ****************************************************}
{ }
{ This numeric report object displays the value }
{ of a double variable (with format :fmt1:fmt2), }
{ given the address of the variable. }
{ }
{#F ****************************************************}
Data: ^double;
Fmt1, Fmt2: byte;
constructor Init(var Bounds: TRect;
var AData: double;
AFmt1, AFmt2: byte
{Display as in write(AData: AFmt1: AFmt2) }
);
procedure GetText(var S: string); virtual;
function DataSize: word; virtual;
end;
const
cmNewSelect = 100;
type
PMRadioButtons = ^TMRadioButtons;
TMRadioButtons = object(TRadioButtons)
{#F ****************************************************}
{ }
{ This variant of the Radio Buttons object broad- }
{ casts a #cmNewSelect# message when the selection }
{ is changed. }
{ }
{#F ****************************************************}
procedure MovedTo(Item: integer); virtual;
procedure Press(Item: integer); virtual;
end;
{#T simple_input_lines}
{#F ****************************************************
Objects for inputting numbers, for use in dialogs;
for all predefined integer and real types:
shortint, byte, integer, word, longint,
real, single, double, extended, comp
All objects are derived from InputLine object.
All objects have the same syntax.
Use inFmt1 and inFmt2 to control output format.
No special editing; invalid input is set to zero.
String lengths are given names of the form:
inTypeLen such as inShortintLen
#F ****************************************************}
const
{ string lengths: }
inShortintLen = 4;
inByteLen = 3;
inIntegerLen = 6;
inWordLen = 5;
inLongintLen = 11;
inRealLen = 22;
inSingleLen = 18;
inDoubleLen = 27;
inExtendedLen = 32;
inCompLen = 20;
const
{ format options (as in "v:fmt1:fmt2"): }
inFmt1: word = 0;
inFmt2: word = 6;
type
PInputShortint = ^TInputShortint;
TInputShortint = object(TInputLine)
{See #simple_input_lines#.}
NumMode: boolean;
constructor Init(Bounds: TRect);
procedure SetData(var AData); virtual;
procedure GetData(var AData); virtual;
function DataSize: word; virtual;
end;
type
PInputByte = ^TInputByte;
TInputByte = object(TInputLine)
{See #simple_input_lines#.}
NumMode: boolean;
constructor Init(Bounds: TRect);
procedure SetData(var AData); virtual;
procedure GetData(var AData); virtual;
function DataSize: word; virtual;
end;
type
PInputInteger = ^TInputInteger;
TInputInteger = object(TInputLine)
{See #simple_input_lines#.}
NumMode: boolean;
constructor Init(Bounds: TRect);
procedure SetData(var AData); virtual;
procedure GetData(var AData); virtual;
function DataSize: word; virtual;
end;
type
PInputWord = ^TInputWord;
TInputWord = object(TInputLine)
{See #simple_input_lines#.}
NumMode: boolean;
constructor Init(Bounds: TRect);
procedure SetData(var AData); virtual;
procedure GetData(var AData); virtual;
function DataSize: word; virtual;
end;
type
PInputLongint = ^TInputLongint;
TInputLongint = object(TInputLine)
{See #simple_input_lines#.}
NumMode: boolean;
constructor Init(Bounds: TRect);
procedure SetData(var AData); virtual;
procedure GetData(var AData); virtual;
function DataSize: word; virtual;
end;
type
PInputReal = ^TInputReal;
TInputReal = object(TInputLine)
{See #simple_input_lines#.}
NumMode: boolean;
constructor Init(Bounds: TRect);
procedure SetData(var AData); virtual;
procedure GetData(var AData); virtual;
function DataSize: word; virtual;
end;
type
PInputSingle = ^TInputSingle;
TInputSingle = object(TInputLine)
{See #simple_input_lines#.}
NumMode: boolean;
constructor Init(Bounds: TRect);
procedure SetData(var AData); virtual;
procedure GetData(var AData); virtual;
function DataSize: word; virtual;
end;
type
PInputDouble = ^TInputDouble;
TInputDouble = object(TInputLine)
{See #simple_input_lines#.}
NumMode: boolean;
constructor Init(Bounds: TRect);
procedure SetData(var AData); virtual;
procedure GetData(var AData); virtual;
function DataSize: word; virtual;
end;
type
PInputExtended = ^TInputExtended;
TInputExtended = object(TInputLine)
{See #simple_input_lines#.}
NumMode: boolean;
constructor Init(Bounds: TRect);
procedure SetData(var AData); virtual;
procedure GetData(var AData); virtual;
function DataSize: word; virtual;
end;
type
PInputComp = ^TInputComp;
TInputComp = object(TInputLine)
{See #simple_input_lines#.}
NumMode: boolean;
constructor Init(Bounds: TRect);
procedure SetData(var AData); virtual;
procedure GetData(var AData); virtual;
function DataSize: word; virtual;
end;
{*******************************************************}
implementation
uses Drivers, Views, App;
{ execute given dialog with given data: }
function ExecDialog(P: PDialog; Data: Pointer): Word;
var
Cmd: Word;
begin
Cmd:= cmCancel;
P:= PDialog(Application^.ValidView(P));
if P <> nil then begin
if Data <> nil then P^.SetData(Data^);
Cmd:= DeskTop^.ExecView(P);
if (Cmd <> cmCancel) and (Data <> nil)
then P^.GetData(Data^);
Dispose(P, Done);
end;
ExecDialog:= Cmd;
end; {ExecDialog}
{*******************************************************}
{ TIndexedText }
constructor TIndexedText.Init(var Bounds: TRect; var AText;
var AIndex: word);
begin
TStaticText.Init(Bounds, '');
TextArray:= @AText;
Index:= @AIndex;
end; {TIndexedText.Init}
procedure TIndexedText.GetText(var S: string);
var
P: byte;
begin
S:= TextArray^[Index^];
repeat
P:= Pos('~', S);
if P > 0 then Delete(S, P, 1);
until P = 0;
end; {TIndexedText.GetText}
function TIndexedText.DataSize: word;
begin
DataSize:= 0;
end; {TIndexedText.DataSize}
{*******************************************************}
{ TNumReport - numeric report object }
constructor TNumReport.Init(var Bounds: TRect;
var AData: double;
AFmt1, AFmt2: byte
);
begin
TStaticText.Init(Bounds, '');
Data:= @AData;
Fmt1:= AFmt1;
Fmt2:= AFmt2;
end; {TNumReport.Init}
procedure TNumReport.GetText(var S: string);
begin
Str(Data^: Fmt1: Fmt2, S);
end; {TNumReport.GetText}
function TNumReport.DataSize: word;
begin
DataSize:= 0;
end; {TNumReport.DataSize}
{*******************************************************}
{ Radio Buttons variant that broadcasts cmNewSelect message: }
{ used to respond to up, down arrow keys: }
procedure TMRadioButtons.MovedTo(Item: integer);
var
NewSel: longint;
begin
TRadioButtons.MovedTo(Item);
NewSel:= Item;
Message(TopView, evBroadcast, cmNewSelect, Pointer(NewSel));
end; {TMRadioButtons.MovedTo}
{ used to respond to mouse clicks and shortcut keys: }
procedure TMRadioButtons.Press(Item: integer);
var
NewSel: longint;
begin
TRadioButtons.Press(Item);
NewSel:= Item;
Message(TopView, evBroadcast, cmNewSelect, Pointer(NewSel));
end; {TMRadioButtons.Press}
{*******************************************************}
{ }
{ Objects for inputting numbers, for use in dialogs }
{ }
{*******************************************************}
{ TInputShortint methods: }
constructor TInputShortint.Init(Bounds: TRect);
begin
TInputLine.Init(Bounds, inShortintLen);
NumMode:= true;
end;
procedure TInputShortint.SetData(var AData);
var
S: string[inShortintLen];
V: Shortint absolute AData;
begin
FillChar(S[1], inShortintLen, ' ');
Str(V: inFmt1, S);
NumMode:= false;
TInputLine.SetData(S);
NumMode:= true;
end;
procedure TInputShortint.GetData(var AData);
var
S: string[inShortintLen];
V: Shortint absolute AData;
E: integer;
begin
NumMode:= false;
TInputLine.GetData(S);
NumMode:= true;
while (Length(S) > 0) and (S[1] = ' ') do Delete(S, 1, 1);
Val(S, V, E);
if E <> 0 then V:= 0;
end;
function TInputShortint.DataSize: word;
begin
if NumMode then begin
DataSize:= SizeOf(Shortint);
end else begin
DataSize:= TInputLine.DataSize;
end;
end;
{ TInputByte methods: }
constructor TInputByte.Init(Bounds: TRect);
begin
TInputLine.Init(Bounds, inByteLen);
NumMode:= true;
end;
procedure TInputByte.SetData(var AData);
var
S: string[inByteLen];
V: Byte absolute AData;
begin
FillChar(S[1], inByteLen, ' ');
Str(V: inFmt1, S);
NumMode:= false;
TInputLine.SetData(S);
NumMode:= true;
end;
procedure TInputByte.GetData(var AData);
var
S: string[inByteLen];
V: Byte absolute AData;
E: integer;
begin
NumMode:= false;
TInputLine.GetData(S);
NumMode:= true;
while (Length(S) > 0) and (S[1] = ' ') do Delete(S, 1, 1);
Val(S, V, E);
if E <> 0 then V:= 0;
end;
function TInputByte.DataSize: word;
begin
if NumMode then begin
DataSize:= SizeOf(Byte);
end else begin
DataSize:= TInputLine.DataSize;
end;
end;
{ TInputInteger methods: }
constructor TInputInteger.Init(Bounds: TRect);
begin
TInputLine.Init(Bounds, inIntegerLen);
NumMode:= true;
end;
procedure TInputInteger.SetData(var AData);
var
S: string[inIntegerLen];
V: Integer absolute AData;
begin
FillChar(S[1], inIntegerLen, ' ');
Str(V: inFmt1, S);
NumMode:= false;
TInputLine.SetData(S);
NumMode:= true;
end;
procedure TInputInteger.GetData(var AData);
var
S: string[inIntegerLen];
V: Integer absolute AData;
E: integer;
begin
NumMode:= false;
TInputLine.GetData(S);
NumMode:= true;
while (Length(S) > 0) and (S[1] = ' ') do Delete(S, 1, 1);
Val(S, V, E);
if E <> 0 then V:= 0;
end;
function TInputInteger.DataSize: word;
begin
if NumMode then begin
DataSize:= SizeOf(Integer);
end else begin
DataSize:= TInputLine.DataSize;
end;
end;
{ TInputWord methods: }
constructor TInputWord.Init(Bounds: TRect);
begin
TInputLine.Init(Bounds, inWordLen);
NumMode:= true;
end;
procedure TInputWord.SetData(var AData);
var
S: string[inWordLen];
V: Word absolute AData;
begin
FillChar(S[1], inWordLen, ' ');
Str(V: inFmt1, S);
NumMode:= false;
TInputLine.SetData(S);
NumMode:= true;
end;
procedure TInputWord.GetData(var AData);
var
S: string[inWordLen];
V: Word absolute AData;
E: integer;
begin
NumMode:= false;
TInputLine.GetData(S);
NumMode:= true;
while (Length(S) > 0) and (S[1] = ' ') do Delete(S, 1, 1);
Val(S, V, E);
if E <> 0 then V:= 0;
end;
function TInputWord.DataSize: word;
begin
if NumMode then begin
DataSize:= SizeOf(Word);
end else begin
DataSize:= TInputLine.DataSize;
end;
end;
{ TInputLongint methods: }
constructor TInputLongint.Init(Bounds: TRect);
begin
TInputLine.Init(Bounds, inLongintLen);
NumMode:= true;
end;
procedure TInputLongint.SetData(var AData);
var
S: string[inLongintLen];
V: Longint absolute AData;
begin
FillChar(S[1], inLongintLen, ' ');
Str(V: inFmt1, S);
NumMode:= false;
TInputLine.SetData(S);
NumMode:= true;
end;
procedure TInputLongint.GetData(var AData);
var
S: string[inLongintLen];
V: Longint absolute AData;
E: integer;
begin
NumMode:= false;
TInputLine.GetData(S);
NumMode:= true;
while (Length(S) > 0) and (S[1] = ' ') do Delete(S, 1, 1);
Val(S, V, E);
if E <> 0 then V:= 0;
end;
function TInputLongint.DataSize: word;
begin
if NumMode then begin
DataSize:= SizeOf(Longint);
end else begin
DataSize:= TInputLine.DataSize;
end;
end;
{ TInputReal methods: }
constructor TInputReal.Init(Bounds: TRect);
begin
TInputLine.Init(Bounds, inRealLen);
NumMode:= true;
end;
procedure TInputReal.SetData(var AData);
var
S: string[inRealLen];
V: Real absolute AData;
begin
FillChar(S[1], inRealLen, ' ');
Str(V: inFmt1: inFmt2, S);
NumMode:= false;
TInputLine.SetData(S);
NumMode:= true;
end;
procedure TInputReal.GetData(var AData);
var
S: string[inRealLen];
V: Real absolute AData;
E: integer;
begin
NumMode:= false;
TInputLine.GetData(S);
NumMode:= true;
while (Length(S) > 0) and (S[1] = ' ') do Delete(S, 1, 1);
Val(S, V, E);
if E <> 0 then V:= 0.0;
end;
function TInputReal.DataSize: word;
begin
if NumMode then begin
DataSize:= SizeOf(Real);
end else begin
DataSize:= TInputLine.DataSize;
end;
end;
{ TInputSingle methods: }
constructor TInputSingle.Init(Bounds: TRect);
begin
TInputLine.Init(Bounds, inSingleLen);
NumMode:= true;
end;
procedure TInputSingle.SetData(var AData);
var
S: string[inSingleLen];
V: Single absolute AData;
begin
FillChar(S[1], inSingleLen, ' ');
Str(V: inFmt1: inFmt2, S);
NumMode:= false;
TInputLine.SetData(S);
NumMode:= true;
end;
procedure TInputSingle.GetData(var AData);
var
S: string[inSingleLen];
V: Single absolute AData;
E: integer;
begin
NumMode:= false;
TInputLine.GetData(S);
NumMode:= true;
while (Length(S) > 0) and (S[1] = ' ') do Delete(S, 1, 1);
Val(S, V, E);
if E <> 0 then V:= 0.0;
end;
function TInputSingle.DataSize: word;
begin
if NumMode then begin
DataSize:= SizeOf(Single);
end else begin
DataSize:= TInputLine.DataSize;
end;
end;
{ TInputDouble methods: }
constructor TInputDouble.Init(Bounds: TRect);
begin
TInputLine.Init(Bounds, inDoubleLen);
NumMode:= true;
end;
procedure TInputDouble.SetData(var AData);
var
S: string[inDoubleLen];
V: Double absolute AData;
begin
FillChar(S[1], inDoubleLen, ' ');
Str(V: inFmt1: inFmt2, S);
NumMode:= false;
TInputLine.SetData(S);
NumMode:= true;
end;
procedure TInputDouble.GetData(var AData);
var
S: string[inDoubleLen];
V: Double absolute AData;
E: integer;
begin
NumMode:= false;
TInputLine.GetData(S);
NumMode:= true;
while (Length(S) > 0) and (S[1] = ' ') do Delete(S, 1, 1);
Val(S, V, E);
if E <> 0 then V:= 0.0;
end;
function TInputDouble.DataSize: word;
begin
if NumMode then begin
DataSize:= SizeOf(Double);
end else begin
DataSize:= TInputLine.DataSize;
end;
end;
{ TInputExtended methods: }
constructor TInputExtended.Init(Bounds: TRect);
begin
TInputLine.Init(Bounds, inExtendedLen);
NumMode:= true;
end;
procedure TInputExtended.SetData(var AData);
var
S: string[inExtendedLen];
V: Extended absolute AData;
begin
FillChar(S[1], inExtendedLen, ' ');
Str(V: inFmt1: inFmt2, S);
NumMode:= false;
TInputLine.SetData(S);
NumMode:= true;
end;
procedure TInputExtended.GetData(var AData);
var
S: string[inExtendedLen];
V: Extended absolute AData;
E: integer;
begin
NumMode:= false;
TInputLine.GetData(S);
NumMode:= true;
while (Length(S) > 0) and (S[1] = ' ') do Delete(S, 1, 1);
Val(S, V, E);
if E <> 0 then V:= 0.0;
end;
function TInputExtended.DataSize: word;
begin
if NumMode then begin
DataSize:= SizeOf(Extended);
end else begin
DataSize:= TInputLine.DataSize;
end;
end;
{ TInputComp methods: }
constructor TInputComp.Init(Bounds: TRect);
begin
TInputLine.Init(Bounds, inCompLen);
NumMode:= true;
end;
procedure TInputComp.SetData(var AData);
var
S: string[inCompLen];
V: Comp absolute AData;
begin
FillChar(S[1], inCompLen, ' ');
Str(V: inFmt1: inFmt2, S);
NumMode:= false;
TInputLine.SetData(S);
NumMode:= true;
end;
procedure TInputComp.GetData(var AData);
var
S: string[inCompLen];
V: Comp absolute AData;
E: integer;
begin
NumMode:= false;
TInputLine.GetData(S);
NumMode:= true;
while (Length(S) > 0) and (S[1] = ' ') do Delete(S, 1, 1);
Val(S, V, E);
if E <> 0 then V:= 0;
end;
function TInputComp.DataSize: word;
begin
if NumMode then begin
DataSize:= SizeOf(Comp);
end else begin
DataSize:= TInputLine.DataSize;
end;
end;
end.