-
Notifications
You must be signed in to change notification settings - Fork 2
/
test6.pas
124 lines (109 loc) · 3.57 KB
/
test6.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
program webTest;
uses
SysUtils, webUtils;
const
FORMc = '</form>'; // tutupan form
var
inputIndex: integer = 0; // penghitung antarmuka masukan
// uji kondisi 2 teks
function switch(const condition: boolean; const ifTrue, ifFalse: string): string;
begin
if condition then result := ifTrue else result := ifFalse;
end;
// membuat garis pemisah horisontal
function separator: string;
begin
result := '<hr class="separator"/>'
end;
// membuat ruang kosong sebelum masukan
function putSpace(const aLabel: string = ''): string;
begin
result := '<span class="input">'+aLabel+'</span>';
end;
// membuat bukaan form
function formOpen(const action: string; const isPost: boolean = false): string;
begin
result := '<form action="'+action+'" method="'+switch(isPost,'post','get')+'">';
end;
// membuat teks keterangan masukan
function putLabel(const aLabel: string; const forID: string = '_'): string;
begin
result := '<label class="input"';
if forID = '_' then
result += ' for="input_'+IntToStr(inputIndex+1)+'">'
else if forID <> '' then
result += ' for="'+forID+'">'
else
result += '>';
result += aLabel+'</label>';
end;
// membuat masukan teks
function inputText(const aValue: string = ''): string;
begin
inputIndex := inputIndex+1;
result := '<input type="text"'+
' id="input_'+IntToStr(inputIndex)+'"'+
' name="input_'+IntToStr(inputIndex)+'"'+
switch(aValue='','',' value="'+aValue+'"')+'/>';
end;
// membuat masukan bilangan
function inputNumber(const aValue: integer = -1): string;
begin
inputIndex := inputIndex+1;
result := '<input type="number"'+
' id="input_'+IntToStr(inputIndex)+'"'+
' name="input_'+IntToStr(inputIndex)+'"'+
switch(IntToStr(aValue)='-1','',' value="'+IntToStr(aValue)+'"')+
'/></label>';
end;
// membuat masukan logika
function inputBool(const aCaption: string; const aValue: boolean = false): string;
begin
inputIndex := inputIndex+1;
result := '<label><input type="checkbox"'+
' id="input_'+IntToStr(inputIndex)+'"'+
' name="input_'+IntToStr(inputIndex)+'"'+
' value="true"'+
switch(aValue,' checked','')+
'/> '+aCaption+' </label>';
end;
// membuat masukan memo
function inputMemo(const aValue: string = ''): string;
begin
inputIndex := inputIndex+1;
result := '<textarea'+
' id="input_'+IntToStr(inputIndex)+'"'+
' name="input_'+IntToStr(inputIndex)+'">'+
aValue+'</textarea>';
end;
// membuat masukan tombol
function inputButton(const aCaption: string; const action: string = ''; const isReset: boolean = false): string;
begin
inputIndex := inputIndex+1;
result := '<button'+
' type="'+switch(isReset,'reset','submit')+'"'+
' id="button_'+IntToStr(inputIndex)+'"'+
' name="input_'+IntToStr(inputIndex)+'"'+
switch(action='','',' formaction="'+action+'"')+
' value="clicked">'+aCaption+'</button>';
end;
// menulis isi laman
procedure writeContent;
begin
writeln(Po,formOpen(ExtractFilename(ParamStr(0))));
writeln(putLabel('String: '),inputText,BR);
writeln(putLabel('Number: '),inputNumber,BR);
writeln(putLabel('Boolean: ',''),inputBool('Yes, I agree'),BR);
writeln(putLabel('Memo: '),inputMemo,BR);
writeln(separator);
writeln(putSpace,inputButton(' SUBMIT '),BR);
writeln(FORMc,Pc,HR);
log.debug('#'+{$I %LINE%}+': [main.writeContent] done.');
end;
(*** program utama ***)
begin
writeHeader('Read Input','test.css');
writeTitle('READ INPUT',3);
writeContent;
writeFooter;
end.