-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnit1.pas
More file actions
186 lines (171 loc) · 4.64 KB
/
Unit1.pas
File metadata and controls
186 lines (171 loc) · 4.64 KB
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
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
Vcl.ExtCtrls, Vcl.ComCtrls, SuperObject;
type
TForm1 = class(TForm)
Memo1: TMemo;
TreeView1: TTreeView;
Panel1: TPanel;
Button2: TButton;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure ParseItemsIntoTreeView(node: TTreeNode; itemData: ISuperObject);
function _s(i: integer; padLeftWith0Count: integer = 0): string;
function _i(s: String; default: integer = 0): Integer;
function DateFromSQL(const ASQLDate: String): TDateTime;
function DateIndoShort (const ADate: TDate):String;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
var
s, v: string;
curv,
iso: ISuperObject;
item: TSuperObjectIter;
tvi: TTreeNode;
begin
s := Memo1.Text;
TreeView1.Items.BeginUpdate;
try
TreeView1.Items.Clear;
tvi := TreeView1.Items.AddFirst(nil, 'Parsed Data:');
tvi.ImageIndex := 0;
if (s = '') or (s = '{}') then
begin
TreeView1.Items.AddChild(tvi, 'Tidak ada data...').ImageIndex := 5;
end
else
begin
iso := so(s);
ParseItemsIntoTreeView(tvi, iso);
end;
finally
TreeView1.Items.EndUpdate;
TreeView1.Items[0].Expand(false);
TreeView1.Items[0].MakeVisible;
end;
end;
function TForm1.DateFromSQL(const ASQLDate: String): TDateTime;
begin
try
Result := EncodeDate(
_i(Copy(ASQLDate,1,4)),
_i(Copy(ASQLDate,6,2)),
_i(Copy(ASQLDate,9,2))
);
except
Result := Date();
end;
end;
function TForm1.DateIndoShort(const ADate: TDate): String;
begin
Result := FormatDateTime('dd/MM/yyyy', ADate);
end;
procedure TForm1.ParseItemsIntoTreeView(node: TTreeNode; itemData: ISuperObject);
var
curv: ISuperObject;
cura: TSuperArray;
item: TSuperObjectIter;
tvi: TTreeNode;
s, v, dv: string;
i: integer;
begin
try
if ObjectFindFirst(itemData, item) then
repeat
s := item.key;
v := '';
if item.val.IsType(stString) then
begin
v := item.val.AsString;
dv := copy(v,1,10);
// '2020-06-04'
if
(length(dv)>=10) and
(dv[5] = '-') and (dv[8] = '-') and
(_s(_i( copy(dv,1,4) ,0)) = copy(dv,1,4)) and
(_s(_i( copy(dv,6,2) ,0),2) = copy(dv,6,2)) and
(_s(_i( copy(dv,9,2) ,0),2) = copy(dv,9,2))
then
begin
TreeView1.Items.AddChild(node, s+': '+DateIndoShort(DateFromSQL(dv))+' '+copy(v,11,length(v)))
end
else
TreeView1.Items.AddChild(node, s+': '+v)
end
else
if item.val.IsType(stBoolean) then
begin
v := BoolToStr(item.val.AsBoolean, true);
TreeView1.Items.AddChild(node, s+': '+v)
end
else
if item.val.IsType(stInt) then
begin
v := FloatToStr( item.val.AsInteger);
TreeView1.Items.AddChild(node, s+': '+v)
end
else
if item.val.IsType(stDouble) then
begin
v := FloatToStr( item.val.AsDouble);
TreeView1.Items.AddChild(node, s+': '+v)
end
else
if item.val.IsType(stCurrency) then
begin
v := FloatToStr (item.val.AsCurrency);
TreeView1.Items.AddChild(node, s+': '+v)
end
else
if item.val.IsType(stNull) then
begin
v := '';
TreeView1.Items.AddChild(node, s+': '+v)
end
else
if item.val.IsType(stObject) then
begin
v := item.val.AsString();
tvi := TreeView1.Items.AddChild(node, s+':');
ParseItemsIntoTreeView(tvi, item.val);
end
else
if item.val.IsType(stArray) then
begin
v := item.val.AsString();
cura := item.val.AsArray;
tvi := TreeView1.Items.AddChild(node, s+':');
for i := 0 to cura.Length-1 do
begin
ParseItemsIntoTreeView(TreeView1.Items.AddChild(tvi, _s(i+1)+'.:'), cura[i] );
end;
end;
until not ObjectFindNext(item);
finally
end;
end;
function TForm1._i(s: String; default: integer = 0): Integer;
begin
Result := StrToIntDef(s, default);
end;
function TForm1._s(i: integer; padLeftWith0Count: integer = 0): string;
begin
Result := IntToStr(i);
if padLeftWith0Count> 0 then
begin
while length(Result)<padLeftWith0Count do
Result := '0' + Result;
end;
end;
end.