├── .gitignore
├── JsonDataObjects.pas
├── PascalObjectSeralize.identcache
├── PascalObjectSeralize.stat
├── README.md
├── backup
├── fpc_seralizeadapter.pas
├── intf_seralizeadapter.pas
└── pascalobject_seralize.pas
├── delphi_seralizeadapter.pas
├── delphi_test
├── PascalObjectSeralize.dpr
├── PascalObjectSeralize.dproj
├── PascalObjectSeralize.dproj.local
├── PascalObjectSeralize.identcache
├── PascalObjectSeralize.res
├── PascalObjectSeralize.skincfg
├── PascalObjectSeralize.stat
├── Testpascalobject_seralize.pas
├── frm_test.dfm
├── frm_test.pas
├── testPascalObjectSeralize.dpr
├── testPascalObjectSeralize.dproj
├── testPascalObjectSeralize.dproj.local
├── testPascalObjectSeralize.identcache
├── testPascalObjectSeralize.res
├── testPascalObjectSeralize.skincfg
└── testPascalObjectSeralize.stat
├── fpc_seralizeadapter.pas
├── intf_seralizeadapter.pas
├── pascalobject_seralize.pas
└── test
├── backup
├── frm_test.lfm
├── pascalobject_seralize_test.lpi
├── pascalobject_seralize_test.lpr
├── pascalobject_seralize_test.lps
├── test_pascalobjectseralize.pas
└── testfpc_seralizeadapter_test.pas
├── frm_test.lfm
├── frm_test.pas
├── pascalobject_seralize_test.compiled
├── pascalobject_seralize_test.fpcunit.ini
├── pascalobject_seralize_test.ico
├── pascalobject_seralize_test.lpi
├── pascalobject_seralize_test.lpr
├── pascalobject_seralize_test.lps
├── pascalobject_seralize_test.res
├── test_pascalobjectseralize.pas
├── testcase1.pas
├── testdata
├── test.png
├── test.xml
└── testCollection.xml
└── testfpc_seralizeadapter_test.pas
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *.ppu
3 | *.exe
4 | *.dbg
5 | *.or
6 | lib/
7 | DEBUG/
8 | RELEASE/
9 | __history/
10 | *.dcu
11 | *.json
12 | *.png
13 | *.xml
14 | *.bak
15 | __recovery/
16 |
--------------------------------------------------------------------------------
/PascalObjectSeralize.identcache:
--------------------------------------------------------------------------------
1 | 7E:\GitHub\PascalObjectSeralize\PascalObjectSeralize.dpr
--------------------------------------------------------------------------------
/PascalObjectSeralize.stat:
--------------------------------------------------------------------------------
1 | [Stats]
2 | EditorSecs=1
3 | DesignerSecs=1
4 | InspectorSecs=1
5 | CompileSecs=1
6 | OtherSecs=1
7 | StartTime=2018/3/8 10:05:25
8 | RealKeys=0
9 | EffectiveKeys=0
10 | DebugSecs=1
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PascalObjectSeralize
2 | Seralize a Object to xml or json file support lazarus Delphi
3 |
--------------------------------------------------------------------------------
/backup/fpc_seralizeadapter.pas:
--------------------------------------------------------------------------------
1 | unit fpc_seralizeadapter;
2 | {$mode objfpc}{$H+}
3 | interface
4 |
5 | uses
6 | Classes, SysUtils, variants,
7 | fpjson, dbugintf,Laz_XMLRead, Laz2_DOM, Laz_XMLWrite,
8 | intf_seralizeadapter;
9 | type
10 |
11 | { TFPCXmlNode }
12 | TFPCXmlNode=class(TInterfacedObject,IDataNode)
13 |
14 |
15 | function GetAttributes(Name: string): string;
16 | function GetChildItem(Index:integer): IDataNode;
17 | function GetNodeName: string;
18 | function GetValue: variant;
19 | procedure SetAttributes(Name: string; AValue: string);
20 | procedure SetNodeName(AValue: string);
21 | procedure SetValue(AValue: variant);
22 | function AddChild():IDataNode;
23 | function ChildCount:integer;
24 | procedure SetData(AValue: string);
25 | function AddPropObj(const Name: string): IDataNode;
26 | function PropObjByName(const Name:string): IDataNode;
27 | function GetData: string;
28 | function GetDumpText:string;
29 | protected
30 | fDoc:TDOMDocument;
31 | fNode:TDOMNode;
32 | function BuilDataNode(const Node:TDOMNode):IDataNode;
33 | end;
34 | {TFPCJsonNode=class(TInterfacedObject,IDataNode)
35 |
36 | end;}
37 |
38 |
39 | { TFPCXmlAdapter }
40 |
41 | TFPCXmlAdapter=class(TInterfacedObject,IDataAdapter)
42 |
43 |
44 |
45 | function NewDoc:IDataNode;
46 | function GetRootNode:IDataNode;
47 | procedure LoadFromFile(const Filename:string);
48 | procedure SaveToFile(const FileName:string);
49 | function GetSeralzieString: string;
50 | private
51 | fDoc:TXMLDocument;
52 | public
53 | destructor Destroy;override;
54 |
55 | end;
56 | TFPCJsonNode=class(TInterfacedObject,IDataNode)
57 | function GetAttributes(Name: string): string;
58 | function GetChildItem(Index:integer): IDataNode;
59 | function GetNodeName: string;
60 | function GetValue: variant;
61 | procedure SetAttributes(Name: string; AValue: string);
62 | procedure SetNodeName(AValue: string);
63 | procedure SetValue(AValue: variant);
64 | function AddChild():IDataNode;
65 | function ChildCount:integer;
66 | procedure SetData(AValue: string);
67 | function GetData: string;
68 | function AddPropObj(const Name: string): IDataNode;
69 | function PropObjByName(const Name:string): IDataNode;
70 | function GetDumpText:string;
71 | protected
72 | fDoc:TJsonObject;
73 | fNode:TJSOnData;
74 | FParent:TJsonObject;
75 | function BuilDataNode(const Node:TJsonData):IDataNode;
76 | end;
77 |
78 | { TFPCJsonAdapter }
79 |
80 | TFPCJsonAdapter=class(TInterfacedObject,IDataAdapter)
81 | function NewDoc:IDataNode;
82 | function GetRootNode:IDataNode;
83 | procedure LoadFromFile(const Filename:string);
84 | procedure SaveToFile(const FileName:string);
85 | function GetSeralzieString: string;
86 | private
87 | fDoc:TJsonObject;
88 | public
89 | destructor Destroy;override;
90 | end;
91 | implementation
92 |
93 | { TFPCJsonNode }
94 |
95 | function TFPCJsonNode.GetAttributes(Name: string): string;
96 | begin
97 | if FNode is TJSonData then
98 | begin
99 | result :=(FNode as TJsonObject).Get(LowerCase(Name));
100 | end else
101 | begin
102 | assert(false,'fnode is not a object');
103 | end;
104 | end;
105 |
106 | function TFPCJsonNode.GetChildItem(Index: integer): IDataNode;
107 | var
108 | Item:TJsonObject;
109 | Count:integer;
110 | JObj:TJsonObject;
111 | Arr:TJSONArray;
112 | begin
113 | JObj :=FNode as TJsonObject;
114 | Arr :=JObj.Arrays['ITEMS'];
115 | Item :=Arr.Objects[Index];
116 | result :=BuilDataNode(Item);
117 | end;
118 |
119 | function TFPCJsonNode.GetNodeName: string;
120 | var
121 | Index:integer;
122 | begin
123 | Index :=FParent.IndexOf(FNode);
124 | result :=FParent.Names[Index];
125 |
126 | end;
127 |
128 | function TFPCJsonNode.GetValue: variant;
129 | begin
130 | result :=FNode.Value;
131 | end;
132 |
133 | procedure TFPCJsonNode.SetAttributes(Name: string; AValue: string);
134 | var
135 | JD:TJSOnData;
136 | Jobj:TJsonObject;
137 | begin
138 | if FNode is TJsonObject then
139 | begin
140 | JObj :=FNode as TJsonObject;
141 | JD :=Jobj.Find(LowerCase(Name));
142 | if not Assigned(JD)then
143 | begin
144 | (FNode as TJsonObject).Add(LowerCase(Name),AValue);
145 | end else
146 | begin
147 | jd.AsString:=AValue;
148 | end;
149 | end;
150 | end;
151 |
152 | procedure TFPCJsonNode.SetNodeName(AValue: string);
153 | begin
154 | (FNode as TJsonObject).Find('name').Value :=AVAlue;
155 | end;
156 |
157 | procedure TFPCJsonNode.SetValue(AValue: variant);
158 |
159 | begin
160 | FNode.Value:=AValue;
161 |
162 | end;
163 |
164 | function TFPCJsonNode.AddChild(): IDataNode;
165 | var
166 | JObj:TJsonObject;
167 | Child:TJsonObject;
168 | JNode:TFPCJsonNode;
169 | JArr:TJSONArray;
170 | begin
171 | JObj :=FNode as TJsonObject;
172 | if not JObj.Find('ITEMS',JArr) then
173 | begin
174 | JArr :=TJSONArray.Create;
175 | JObj.Add('ITEMS',JArr);
176 | end;
177 |
178 | Child :=TJsonObject.Create();
179 | JArr.Add(Child);
180 | result :=BuilDataNode(Child);
181 | end;
182 |
183 | function TFPCJsonNode.ChildCount: integer;
184 | var
185 | JObj:TJsonObject;
186 | Arr:TJSONArray;
187 | begin
188 | JObj :=fNode as TJsonObject;
189 | Arr :=Jobj.Arrays['ITEMS'];
190 | result :=Arr.Count;
191 | end;
192 |
193 |
194 |
195 | procedure TFPCJsonNode.SetData(AValue: string);
196 | begin
197 | (FNode as TJSonObject).Add('cdata',AValue);
198 | end;
199 |
200 | function TFPCJsonNode.GetData: string;
201 | begin
202 | result :=(FNode as TJsonObject).Get('cdata');
203 | end;
204 |
205 | function TFPCJsonNode.AddPropObj(const Name: string): IDataNode;
206 | var
207 | JObj,Child:TJsonObject;
208 | begin
209 |
210 | JObj :=FNode as TJsonObject;
211 | Child :=TJsonObject.Create;
212 | Jobj.Add(Name,Child);
213 | Result :=self.BuilDataNode(child);
214 |
215 | end;
216 |
217 | function TFPCJsonNode.PropObjByName(const Name: string): IDataNode;
218 | var
219 | JObj,PropObj :TJsonObject;
220 | begin
221 | JObj :=FNode as TJsonObject;
222 | if JObj.Find(LowerCase(Name),PropObj) then
223 | begin
224 | result :=BuilDataNode(PropObj);
225 | end else
226 | begin
227 | result :=nil;
228 | end;
229 | end;
230 |
231 | function TFPCJsonNode.GetDumpText: string;
232 | begin
233 | result :=FNode.AsJSON;
234 | end;
235 |
236 |
237 |
238 |
239 |
240 | function TFPCJsonNode.BuilDataNode(const Node: TJsonData): IDataNode;
241 | var
242 | JNode:TFPCJsonNode;
243 | begin
244 | JNode :=TFPCJsonNode.Create;
245 | JNode.fDoc :=self.fDoc;
246 | JNode.fNode :=Node;
247 | //JNode.FParent :=FNode as TJsonObject;
248 | result :=JNode;
249 | end;
250 |
251 | { TFPCJsonAdapter }
252 |
253 | function TFPCJsonAdapter.NewDoc: IDataNode;
254 | begin
255 | Fdoc :=GetJson('{JSONOBJECT:{}}') as TJsonObject;
256 | end;
257 |
258 | function TFPCJsonAdapter.GetRootNode: IDataNode;
259 | var
260 | Node:TFPCJsonNode;
261 | JObj:TJsonObject;
262 | begin
263 | JObj :=FDoc.Find('JSONOBJECT') as TJsonObject;
264 | Node :=TFPCJsonNode.Create;
265 | Node.fNode :=JObj;
266 | Node.FParent :=FDoc;
267 | Node.fDoc :=fDOc;
268 | result :=Node;
269 | end;
270 |
271 | procedure TFPCJsonAdapter.LoadFromFile(const Filename: string);
272 | var
273 | FS:TFileStream;
274 | begin
275 | FS :=TFileStream.Create(FileName,fmopenRead);
276 | try
277 | FS.Position:=0;
278 | if not Assigned(Fdoc) then FreeAndNil(FDoc);
279 | FDoc :=GetJson(FS) as TJsonObject;
280 | finally
281 | FreeAndNil(FS);
282 | end;
283 | end;
284 |
285 | procedure TFPCJsonAdapter.SaveToFile(const FileName: string);
286 | var
287 | FS:TFileStream;
288 | begin
289 | FS :=TFileStream.Create(FileName,fmcreate);
290 | try
291 | //FDoc.FormatJSON([foUseTabchar,foSkipWhiteSpace]);
292 | FDoc.FormatJSON(DefaultFormat);
293 | Fdoc.DumpJSON(FS);
294 |
295 | finally
296 | FreeAndNil(FS);
297 | end;
298 | end;
299 |
300 | function TFPCJsonAdapter.GetSeralzieString: string;
301 | begin
302 | result :=fdoc.AsString;
303 | end;
304 |
305 | destructor TFPCJsonAdapter.Destroy;
306 | begin
307 | if Assigned(FDoc) then
308 | FreeAndNil(FDoc);
309 | inherited ;
310 | end;
311 |
312 | { TFPCXmlNode }
313 |
314 | function TFPCXmlNode.BuilDataNode(const Node: TDOMNode): IDataNode;
315 | var
316 | xmlNode:TFPCXmlNode;
317 | begin
318 | xmlNode :=TFpcXmlNode.Create;
319 | xmlNode.fDoc :=self.fDoc;
320 | xmlnode.fNode :=Node;
321 | result :=xmlNode;
322 |
323 | end;
324 |
325 | function TFPCXmlNode.GetAttributes(Name: string): string;
326 | begin
327 | result :=fNode.Attributes.GetNamedItem(Name).NodeValue;
328 | end;
329 |
330 | function TFPCXmlNode.GetChildItem(Index: integer): IDataNode;
331 | var
332 | Node:TDOMNode;
333 | begin
334 | //result :=fNode.ChildNodes[Index];
335 | Node :=fNode.ChildNodes[Index];
336 | result :=self.BuilDataNode(Node);
337 | end;
338 |
339 | function TFPCXmlNode.GetNodeName: string;
340 | begin
341 | result :=fNode.NodeName;
342 | end;
343 |
344 | function TFPCXmlNode.GetValue: variant;
345 | begin
346 | result :=fNode.NodeValue;
347 | end;
348 |
349 | procedure TFPCXmlNode.SetAttributes(Name: string; AValue: string);
350 | var
351 | attr:TDOMNode;
352 | begin
353 | attr :=FNode.Attributes.GetNamedItem(Name);
354 | if Assigned(Attr) then
355 | begin
356 | attr.NodeValue:=AValue;
357 | end else
358 | begin
359 | if fNode is TDOMElement then
360 | begin
361 | (fNode as TDOMElement).SetAttribute(Name,AValue);
362 | end else
363 | begin
364 | assert(false,'this nod is not a element node');
365 | end;
366 | end;
367 | end;
368 |
369 | procedure TFPCXmlNode.SetNodeName(AValue: string);
370 | begin
371 | //
372 | end;
373 |
374 | procedure TFPCXmlNode.SetValue(AValue: variant);
375 | begin
376 | fNode.NodeValue :=VarTostr(AValue);
377 | end;
378 |
379 |
380 |
381 |
382 | function TFPCXmlNode.AddChild(): IDataNode;
383 | var
384 | Ele:TDomElement;
385 | begin
386 | Ele :=FDoc.CreateElement('ITEM');
387 | fNode.AppendChild(Ele);
388 | result :=self.BuilDataNode(Ele);
389 | end;
390 |
391 | function TFPCXmlNode.ChildCount: integer;
392 | begin
393 | result :=FNode.ChildNodes.Count;
394 | end;
395 |
396 |
397 |
398 | procedure TFPCXmlNode.SetData(AValue: string);
399 | var
400 | xmlNode :TFPCXmlNode;
401 | CData:TDOMCDataSection;
402 | begin
403 | CData :=fDoc.CreateCDATASection(AVAlue);
404 | fNode.AppendChild(CData);
405 |
406 |
407 | end;
408 |
409 | function TFPCXmlNode.AddPropObj(const Name: string): IDataNode;
410 | var
411 | Ele:TDOMElement;
412 | begin
413 | Ele :=FDoc.CreateElement(Name);
414 | FNode.AppendChild(Ele);
415 | Result :=self.BuilDataNode(Ele);
416 |
417 | end;
418 |
419 | function TFPCXmlNode.PropObjByName(const Name: string): IDataNode;
420 | var
421 | Node:TDOMNode;
422 | begin
423 | {JObj :=FJSon.O[Name];
424 | if Assigned(JObj) then
425 | begin
426 | result :=BuildDataNode(JObj)
427 | end else
428 | begin
429 | result :=nil;
430 | end; }
431 | Node :=FDoc.FindNode(Name);
432 | if Assigned(Node) then
433 | begin
434 | result :=self.BuilDataNode(Node);
435 | end else
436 | begin
437 | result :=nil;
438 | end;
439 | end;
440 |
441 | function TFPCXmlNode.GetData: string;
442 | begin
443 | result :=FNode.FindNode('#cdata-section').NodeValue;
444 | end;
445 |
446 | function TFPCXmlNode.GetDumpText: string;
447 | begin
448 | result :=self.fNode.TextContent;
449 | end;
450 |
451 |
452 |
453 | { TFPCXmlAdapter }
454 |
455 | destructor TFPCXmlAdapter.Destroy;
456 | begin
457 | if Assigned(fDoc) then
458 | FreeAndNil(fDoc);
459 | inherited ;
460 | end;
461 |
462 | function TFPCXmlAdapter.NewDoc: IDataNode;
463 | var
464 | Element:TDomElement;
465 | begin
466 | if Assigned(fDoc) then
467 | begin
468 | FreeAndNil(fDoc);
469 | end;
470 | fDoc :=TXMLDocument.Create;
471 | Element :=fdoc.CreateElement('XMLObject');
472 | Fdoc.AppendChild(Element);
473 | end;
474 |
475 | function TFPCXmlAdapter.GetRootNode: IDataNode;
476 | var
477 | xmlNode:TFPCXmlNode;
478 | begin
479 | xmlNode :=TFPCXmlNode.Create;
480 | xmlNode.fNode :=fDoc.FirstChild;
481 | xmlNode.fDoc :=fDoc;
482 | result :=xmlNode;
483 | end;
484 |
485 | procedure TFPCXmlAdapter.LoadFromFile(const Filename: string);
486 | begin
487 | //
488 | ReadXMLFile(fDoc,FileName);
489 | end;
490 |
491 | procedure TFPCXmlAdapter.SaveToFile(const FileName: string);
492 | begin
493 |
494 | WriteXML(fDoc,FileName);
495 | end;
496 |
497 | function TFPCXmlAdapter.GetSeralzieString: string;
498 | begin
499 | WriteXML(FDoc,result);
500 | end;
501 |
502 |
503 |
504 | end.
505 |
506 |
--------------------------------------------------------------------------------
/backup/intf_seralizeadapter.pas:
--------------------------------------------------------------------------------
1 | unit intf_seralizeadapter;
2 | {$IFDEF PFC}
3 | {$mode objfpc}{$H+}
4 | {$ENDIF}
5 | interface
6 |
7 | uses
8 | Classes, SysUtils;
9 | const
10 | DATA_NODE_INTERFACE='{33427852-44EE-4EA8-A339-29C082DF3499}';
11 | Data_ADAPTER_INTERFACE='{69CFA652-6127-45FC-934E-FD48871E33DF}';
12 | type
13 | { TDataNode }
14 |
15 | { IDataNode }
16 |
17 | IDataNode=Interface(IInterface)
18 | [DATA_NODE_INTERFACE]
19 | function GetAttributes(Name: string): string;
20 | function GetChildItem(Index:integer): IDataNode;
21 | function GetDumpText: string;
22 | function GetNodeName: string;
23 | function GetValue: variant;
24 | procedure SetAttributes(Name: string; AValue: string);
25 | procedure SetNodeName(AValue: string);
26 | procedure SetValue(AValue: variant);
27 | function AddChild():IDataNode;
28 | function AddPropObj(const Name: string): IDataNode;
29 | function ChildCount:integer;
30 | function PropObjByName(const Name:string): IDataNode;
31 | procedure SetData(AValue: string);
32 | function GetData: string;
33 |
34 | Property ChildItem[Index:integer]:IDataNode read GetChildItem;
35 | Property DATA:string read GetData write SetData;
36 | property NodeName:string read GetNodeName write SetNodeName;
37 | property Value:variant read GetValue write SetValue;
38 | property Attributes[Name:string]:string read GetAttributes write SetAttributes;
39 | property DumpText:string read GetDumpText;
40 | end;
41 |
42 | { IDataAdapter }
43 |
44 | IDataAdapter=interface(IUnknown)
45 | [Data_ADAPTER_INTERFACE]
46 | function NewDoc:IDataNode;
47 | function GetRootNode: IDataNode;
48 | function GetSeralzieString: string;
49 | procedure LoadFromFile(const FileName:string);
50 | procedure SaveToFile(const FileName:string);
51 | property RootNode:IDataNode read GetRootNode;
52 | end;
53 |
54 |
55 |
56 | implementation
57 |
58 |
59 |
60 | { TDataNode }
61 |
62 |
63 |
64 | end.
65 |
66 |
--------------------------------------------------------------------------------
/backup/pascalobject_seralize.pas:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ericwang1104/PascalObjectSeralize/911dcbd0a2ce84cdca8a14b0812758d0133e2ef4/backup/pascalobject_seralize.pas
--------------------------------------------------------------------------------
/delphi_seralizeadapter.pas:
--------------------------------------------------------------------------------
1 | unit delphi_seralizeadapter;
2 |
3 | interface
4 |
5 | uses
6 | Classes,SysUtils,JsonDataObjects,intf_seralizeadapter;
7 |
8 | type
9 | TDJsonNode = class(TInterfacedObject, IDataNode)
10 | strict private
11 | function AddChild: IDataNode;
12 | function AddPropObj(const Name: string): IDataNode;
13 | function PropObjByName(const Name:string): IDataNode;
14 | function ChildCount: integer;
15 | function GetAttributes(Name: string): string;
16 | function GetChildItem(Index:integer): IDataNode;
17 | function GetData: string;
18 | function GetNodeName: string;
19 | function GetValue: variant;
20 | procedure SetAttributes(Name: string; AValue: string);
21 | procedure SetData(AValue: string);
22 | procedure SetNodeName(AValue: string);
23 | procedure SetValue(AValue: variant);
24 | function GetDumpText:string;
25 | private
26 | protected
27 | fDoc: TJsonObject;
28 | FJSon: TJsonObject;
29 | FParent: TJsonObject;
30 | function BuildDataNode(const Node: TJsonObject): IDataNode;
31 | public
32 | end;
33 |
34 | TDJsonAdapter = class(TInterfacedObject, IDataAdapter)
35 | strict private
36 | function GetRootNode: IDataNode;
37 | function GetSeralzieString: string;
38 | procedure LoadFromFile(const FileName:string);
39 | function NewDoc: IDataNode;
40 | procedure SaveToFile(const FileName:string);
41 | private
42 | FJ: TJsonObject;
43 | public
44 | destructor Destroy; override;
45 | end;
46 |
47 | implementation
48 |
49 | destructor TDJsonAdapter.Destroy;
50 | begin
51 | if Assigned(FJ) then
52 | FreeAndNil(FJ);
53 | inherited;
54 | end;
55 |
56 | function TDJsonAdapter.GetRootNode: IDataNode;
57 | var
58 | Node:TDJsonNode;
59 | JObj:TJsonObject;
60 | begin
61 |
62 | JObj := FJ.O['JSONOBJECT'];
63 | Node :=TDJsonNode.Create;
64 | Node.FJSon :=JObj;
65 | Node.FParent :=FJ;
66 | Node.fDoc :=FJ;
67 | result :=Node;
68 | end;
69 |
70 | function TDJsonAdapter.GetSeralzieString: string;
71 | begin
72 | result :=FJ.ToJSON();
73 | end;
74 |
75 | procedure TDJsonAdapter.LoadFromFile(const FileName:string);
76 | begin
77 | if Assigned(FJ) then FreeAndNil(FJ);
78 | FJ :=TJsonObject.Create;
79 | FJ.LoadFromFile(FileName);
80 | end;
81 |
82 | function TDJsonAdapter.NewDoc: IDataNode;
83 | begin
84 | if Assigned(FJ) then FreeAndNil(FJ);
85 | FJ :=TJsonObject.Create;
86 | end;
87 |
88 | procedure TDJsonAdapter.SaveToFile(const FileName:string);
89 | begin
90 | FJ.SaveToFile(FileName,false);
91 |
92 | end;
93 |
94 | function TDJsonNode.AddChild: IDataNode;
95 | var
96 | JObj:TJsonObject;
97 | Arr:TJsonArray;
98 | begin
99 | Arr :=FJSon.A['ITEMS'];
100 | Jobj :=Arr.AddObject;
101 | Result :=BuildDataNode(JObj);
102 | end;
103 |
104 | function TDJsonNode.AddPropObj(const Name: string): IDataNode;
105 | var
106 | JObj:TJsonObject;
107 | begin
108 | JObj :=FJSon.O[LowerCase(Name)];
109 | Result :=BuildDataNode(JObj);
110 | end;
111 |
112 | function TDJsonNode.BuildDataNode(const Node: TJsonObject): IDataNode;
113 | var
114 | JNode:TDJsonNode;
115 | begin
116 | JNode :=TDJsonNode.Create;
117 | JNode.fDoc :=self.fDoc;
118 | JNode.FJSon :=Node;
119 | JNode.FParent := FJSon;
120 | result :=JNode;
121 | end;
122 |
123 | function TDJsonNode.PropObjByName(const Name:string): IDataNode;
124 | var
125 | JObj:TJsonObject;
126 | begin
127 | JObj :=FJSon.O[LowerCase(Name)];
128 | if Assigned(JObj) then
129 | begin
130 | result :=BuildDataNode(JObj)
131 | end else
132 | begin
133 | result :=nil;
134 | end;
135 | end;
136 |
137 | function TDJsonNode.ChildCount: integer;
138 | begin
139 | Result :=FJSon.A['ITEMS'].Count;
140 | end;
141 |
142 | function TDJsonNode.GetAttributes(Name: string): string;
143 | begin
144 | result :=FJSon.S[LowerCase(Name)];
145 | end;
146 |
147 | function TDJsonNode.GetChildItem(Index: integer): IDataNode;
148 | var
149 | Obj:TJsonObject;
150 | begin
151 | Obj :=FJSon.A['ITEMS'].O[Index];
152 | result :=BuildDataNode(Obj);
153 | end;
154 |
155 | function TDJsonNode.GetData: string;
156 | begin
157 | result :=FJSon.Values['cdata'].Value;
158 | end;
159 |
160 | function TDJsonNode.GetDumpText: string;
161 | begin
162 | result :=FJSon.ToJSON(true);
163 | end;
164 |
165 | function TDJsonNode.GetNodeName: string;
166 | begin
167 | result :=FJSon.S['name'];
168 | end;
169 |
170 | function TDJsonNode.GetValue: variant;
171 | begin
172 | result :=FJSon.Values['value'].VariantValue;
173 | end;
174 |
175 | procedure TDJsonNode.SetAttributes(Name, AValue: string);
176 | begin
177 | FJSon.S[LowerCase(Name)] :=AValue;
178 | end;
179 |
180 | procedure TDJsonNode.SetData(AValue: string);
181 | begin
182 | FJSon.Values['cdata'].Value :=AValue;
183 | end;
184 |
185 | procedure TDJsonNode.SetNodeName(AValue: string);
186 | begin
187 | FJSon.S['name'] :=AValue;
188 | end;
189 |
190 | procedure TDJsonNode.SetValue(AValue: variant);
191 | begin
192 | FJSon.Values['value'].VariantValue :=AValue;
193 | end;
194 |
195 | end.
196 |
--------------------------------------------------------------------------------
/delphi_test/PascalObjectSeralize.dpr:
--------------------------------------------------------------------------------
1 | program PascalObjectSeralize;
2 | {
3 |
4 | Delphi DUnit Test Project
5 | -------------------------
6 | This project contains the DUnit test framework and the GUI/Console test runners.
7 | Add "CONSOLE_TESTRUNNER" to the conditional defines entry in the project options
8 | to use the console test runner. Otherwise the GUI test runner will be used by
9 | default.
10 |
11 | }
12 |
13 | {$IFDEF CONSOLE_TESTRUNNER}
14 | {$APPTYPE CONSOLE}
15 | {$ENDIF}
16 |
17 | uses
18 | DUnitTestRunner,
19 | Testpascalobject_seralize in 'Testpascalobject_seralize.pas',
20 | intf_seralizeadapter in '..\intf_seralizeadapter.pas',
21 | JsonDataObjects in '..\JsonDataObjects.pas',
22 | pascalobject_seralize in '..\pascalobject_seralize.pas',
23 | frm_test in 'frm_test.pas' {frmTest},
24 | delphi_seralizeadapter in '..\delphi_seralizeadapter.pas';
25 |
26 | {$R *.RES}
27 |
28 | begin
29 | DUnitTestRunner.RunRegisteredTests;
30 | end.
31 |
32 |
--------------------------------------------------------------------------------
/delphi_test/PascalObjectSeralize.dproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {17B7795F-021E-4379-A893-F9841BB2B9D8}
4 | 18.3
5 | VCL
6 | True
7 | Debug
8 | Win32
9 | 1
10 | Console
11 | PascalObjectSeralize.dpr
12 |
13 |
14 | true
15 |
16 |
17 | true
18 | Base
19 | true
20 |
21 |
22 | true
23 | Base
24 | true
25 |
26 |
27 | true
28 | Base
29 | true
30 |
31 |
32 | true
33 | Base
34 | true
35 |
36 |
37 | true
38 | Cfg_1
39 | true
40 | true
41 |
42 |
43 | true
44 | Base
45 | true
46 |
47 |
48 | .
49 | .\$(Platform)\$(Config)
50 | false
51 | false
52 | false
53 | false
54 | false
55 | RESTBackendComponents;CloudService;soaprtl;soapmidas;RESTComponents;emsclientfiredac;DataSnapFireDAC;FireDACIBDriver;emsclient;FireDACCommon;soapserver;FireDACCommonDriver;inet;FireDAC;FireDACSqliteDriver;$(DCC_UsePackage)
56 | System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace)
57 | $(BDS)\Source\DUnit\src;$(DCC_UnitSearchPath)
58 | _CONSOLE_TESTRUNNER;$(DCC_Define)
59 | PascalObjectSeralize
60 |
61 |
62 | DBXSqliteDriver;tethering;FireDACMSSQLDriver;FireDACDBXDriver;bindengine;FireDACMySQLDriver;DataSnapClient;bindcompdbx;IndyIPServer;dac250;IndySystem;fmxFireDAC;emshosting;FireDACTDataDriver;FMXTee;DbxCommonDriver;xmlrtl;DataSnapNativeClient;fmxobj;rtl;DbxClientDriver;DBXSybaseASADriver;IndyIPClient;FireDACODBCDriver;DataSnapIndy10ServerTransport;DataSnapProviderClient;FireDACMongoDBDriver;DataSnapServerMidas;DBXInterBaseDriver;bindcompfmx;DBXOracleDriver;unidac250;inetdb;FmxTeeUI;emsedge;fmx;fmxdae;dbexpress;IndyCore;dsnap;DataSnapCommon;FireDACOracleDriver;DBXMySQLDriver;DBXFirebirdDriver;FireDACCommonODBC;IndyIPCommon;FireDACPgDriver;ibmonitor;FireDACASADriver;ibxpress;DataSnapServer;ibxbindings;FireDACDSDriver;CustomIPTransport;bindcomp;DBXInformixDriver;dbxcds;dsnapxml;dbrtl;inetdbxpress;IndyProtocols;fmxase;$(DCC_UsePackage)
63 |
64 |
65 | DBXSqliteDriver;dxSpreadSheetCoreDialogsRS25;dxRibbonCustomizationFormRS25;DBXDb2Driver;dxPSPrVwRibbonRS25;dxSkinOffice2007PinkRS25;dxSkinMcSkinRS25;vclactnband;vclFireDAC;cxExportRS25;dxSpreadSheetInplaceRichEditRS25;dxHttpIndyRequestRS25;tethering;dxPScxCommonRS25;FireDACADSDriver;cxPivotGridOLAPRS25;rtcSDK;FireDACMSSQLDriver;cxSchedulerGridRS25;vcltouch;dxSkinDarkRoomRS25;dxSkinDarkSideRS25;vcldb;Intraweb;svn;dxGaugeControlRS25;cxLibraryRS25;dxSkinOffice2007SilverRS25;dxSkinBlackRS25;dxSkinOffice2007BlueRS25;vclib;dxFlowChartAdvancedCustomizeFormRS25;dxSkinOffice2007BlackRS25;FireDACDBXDriver;dxSkinVS2010RS25;vclx;dxSkinFoggyRS25;dxSpreadSheetConditionalFormattingDialogsRS25;dxSkinSevenRS25;dxSkinSpringTimeRS25;dxTileControlRS25;dxMapControlRS25;dxPDFViewerRS25;dxDockingRS25;VCLRESTComponents;cxPageControlRS25;dxSkinLilianRS25;dxPSLnksRS25;dxWizardControlRS25;dxRichEditControlRS25;vclie;bindengine;dxFireDACServerModeRS25;FireDACMySQLDriver;dxSkinOffice2013LightGrayRS25;dxSkinMetropolisRS25;DataSnapClient;rtcSDK_DBA;dxPSdxPDFViewerLnkRS25;dxSkinOffice2016DarkRS25;bindcompdbx;dxSkinBlueprintRS25;dxSkinStardustRS25;DBXSybaseASEDriver;IndyIPServer;dxPSdxLCLnkRS25;dac250;IndySystem;dxSkinOffice2007GreenRS25;TsiLang_XE10r;dsnapcon;VirtualTreesR;dxLayoutControlRS25;dxPSRichEditControlLnkRS25;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;dxdbtrRS25;dxPScxTLLnkRS25;emshosting;dxSpreadSheetRS25;dxSkinVisualStudio2013LightRS25;DBXOdbcDriver;FireDACTDataDriver;FMXTee;cxGridRS25;KGrid_DXER;DbxCommonDriver;CodeSiteLoggingPkg;dxorgcRS25;dxSpreadSheetCoreConditionalFormattingDialogsRS25;dxSkinTheAsphaltWorldRS25;dxSkinHighContrastRS25;dxPScxSchedulerLnkRS25;xmlrtl;DataSnapNativeClient;fmxobj;dxPScxGridLnkRS25;rtl;DbxClientDriver;dacvcl250;DBXSybaseASADriver;dxPSCoreRS25;dxmdsRS25;clinetsuite_xe8;dxSkinOffice2016ColorfulRS25;appanalytics;IndyIPClient;bindcompvcl;dxThemeRS25;TeeUI;VclSmp;FireDACODBCDriver;DataSnapIndy10ServerTransport;DataSnapProviderClient;FireDACMongoDBDriver;cxVerticalGridRS25;dxtrmdRS25;dxADOServerModeRS25;dxSkinPumpkinRS25;DataSnapServerMidas;dxCoreRS25;cxSchedulerTreeBrowserRS25;dxRichEditControlCoreRS25;DBXInterBaseDriver;dxSkinValentineRS25;dxPSTeeChartRS25;svnui;dxSkinOffice2010BlueRS25;dxSkinMoneyTwinsRS25;dxSkinSilverRS25;DBXMSSQLDriver;dxPSdxFCLnkRS25;dxRichEditCoreRS25;DatasnapConnectorsFreePascal;dxSkinOffice2013WhiteRS25;bindcompfmx;DBXOracleDriver;unidac250;inetdb;dxOfficeCoreRS25;FmxTeeUI;emsedge;fmx;fmxdae;dxSkinBlueRS25;dxTabbedMDIRS25;dxBarDBNavRS25;dxPScxPivotGridLnkRS25;dxSkinDevExpressDarkStyleRS25;dbexpress;IndyCore;dxFlowChartRS25;dxRichEditDocumentModelRS25;dsnap;DataSnapCommon;dxBarRS25;dxPSDBTeeChartRS25;dxSkinLiquidSkyRS25;dxdborRS25;DataSnapConnectors;dxPScxExtCommonRS25;cxPivotGridRS25;dxPSdxSpreadSheetLnkRS25;dxSpreadSheetReportDesignerRS25;dxNavBarRS25;cxSchedulerRibbonStyleEventEditorRS25;dxSkinCoffeeRS25;FireDACOracleDriver;DBXMySQLDriver;DBXFirebirdDriver;FireDACCommonODBC;dxSkinOffice2010SilverRS25;cxTreeListRS25;IndyIPCommon;dxSkinLondonLiquidSkyRS25;vcl;dxPScxVGridLnkRS25;dxBarExtItemsRS25;dxSkinsCoreRS25;dxComnRS25;FireDACDb2Driver;dxSkinWhiteprintRS25;dxPSdxDBTVLnkRS25;dxSkinVisualStudio2013BlueRS25;dxSkinGlassOceansRS25;dxSkinMetropolisDarkRS25;dxSkinOffice2013DarkGrayRS25;dxSkinSharpPlusRS25;TeeDB;dxSpreadSheetCoreRS25;dxServerModeRS25;dxPScxPCProdRS25;dxSkinCaramelRS25;DCP_XE7;FireDACPgDriver;ibmonitor;FireDACASADriver;cxEditorsRS25;dxSkiniMaginaryRS25;ibxpress;Tee;CodeSiteDBToolsPkg;DataSnapServer;ibxbindings;dxPsPrVwAdvRS25;vclwinx;FireDACDSDriver;dxSkinSevenClassicRS25;cxDataRS25;dxRichEditInplaceRS25;cxTreeListdxBarPopupMenuRS25;CustomIPTransport;vcldsnap;dxPSdxOCLnkRS25;dxSkinSharpRS25;bindcomp;DBXInformixDriver;cxPivotGridChartRS25;cxSchedulerRS25;dxBarExtDBItemsRS25;dxSkinVisualStudio2013DarkRS25;dxSkinOffice2010BlackRS25;dxDBXServerModeRS25;dxSkinDevExpressStyleRS25;dxGDIPlusRS25;dxPSdxGaugeControlLnkRS25;dbxcds;unidacvcl250;adortl;dxPSdxDBOCLnkRS25;dxRibbonRS25;dsnapxml;dxSpellCheckerRS25;dbrtl;inetdbxpress;IndyProtocols;dxSkinSummer2008RS25;dxPSdxMapControlLnkRS25;dxSkinXmas2008BlueRS25;fmxase;$(DCC_UsePackage)
66 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)
67 | Debug
68 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=
69 | 1033
70 |
71 |
72 | DBXSqliteDriver;dxSpreadSheetCoreDialogsRS25;dxRibbonCustomizationFormRS25;DBXDb2Driver;dxPSPrVwRibbonRS25;dxSkinOffice2007PinkRS25;dxSkinMcSkinRS25;vclactnband;vclFireDAC;cxExportRS25;dxSpreadSheetInplaceRichEditRS25;dxHttpIndyRequestRS25;tethering;dxPScxCommonRS25;FireDACADSDriver;cxPivotGridOLAPRS25;FireDACMSSQLDriver;cxSchedulerGridRS25;vcltouch;dxSkinDarkRoomRS25;dxSkinDarkSideRS25;vcldb;Intraweb;dxGaugeControlRS25;cxLibraryRS25;dxSkinOffice2007SilverRS25;dxSkinBlackRS25;dxSkinOffice2007BlueRS25;vclib;dxFlowChartAdvancedCustomizeFormRS25;dxSkinOffice2007BlackRS25;FireDACDBXDriver;dxSkinVS2010RS25;vclx;dxSkinFoggyRS25;dxSpreadSheetConditionalFormattingDialogsRS25;dxSkinSevenRS25;dxSkinSpringTimeRS25;dxTileControlRS25;dxMapControlRS25;dxPDFViewerRS25;dxDockingRS25;VCLRESTComponents;cxPageControlRS25;dxSkinLilianRS25;dxPSLnksRS25;dxWizardControlRS25;dxRichEditControlRS25;vclie;bindengine;dxFireDACServerModeRS25;FireDACMySQLDriver;dxSkinOffice2013LightGrayRS25;dxSkinMetropolisRS25;DataSnapClient;dxPSdxPDFViewerLnkRS25;dxSkinOffice2016DarkRS25;bindcompdbx;dxSkinBlueprintRS25;dxSkinStardustRS25;DBXSybaseASEDriver;IndyIPServer;dxPSdxLCLnkRS25;dac250;IndySystem;dxSkinOffice2007GreenRS25;dsnapcon;VirtualTreesR;dxLayoutControlRS25;dxPSRichEditControlLnkRS25;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;dxdbtrRS25;dxPScxTLLnkRS25;emshosting;dxSpreadSheetRS25;dxSkinVisualStudio2013LightRS25;DBXOdbcDriver;FireDACTDataDriver;FMXTee;cxGridRS25;DbxCommonDriver;dxorgcRS25;dxSpreadSheetCoreConditionalFormattingDialogsRS25;dxSkinTheAsphaltWorldRS25;dxSkinHighContrastRS25;dxPScxSchedulerLnkRS25;xmlrtl;DataSnapNativeClient;fmxobj;dxPScxGridLnkRS25;rtl;DbxClientDriver;dacvcl250;DBXSybaseASADriver;dxPSCoreRS25;dxmdsRS25;clinetsuite_xe8;dxSkinOffice2016ColorfulRS25;appanalytics;IndyIPClient;bindcompvcl;dxThemeRS25;TeeUI;VclSmp;FireDACODBCDriver;DataSnapIndy10ServerTransport;DataSnapProviderClient;FireDACMongoDBDriver;cxVerticalGridRS25;dxtrmdRS25;dxADOServerModeRS25;dxSkinPumpkinRS25;DataSnapServerMidas;dxCoreRS25;cxSchedulerTreeBrowserRS25;dxRichEditControlCoreRS25;DBXInterBaseDriver;dxSkinValentineRS25;dxPSTeeChartRS25;dxSkinOffice2010BlueRS25;dxSkinMoneyTwinsRS25;dxSkinSilverRS25;DBXMSSQLDriver;dxPSdxFCLnkRS25;dxRichEditCoreRS25;DatasnapConnectorsFreePascal;dxSkinOffice2013WhiteRS25;bindcompfmx;DBXOracleDriver;unidac250;inetdb;dxOfficeCoreRS25;FmxTeeUI;emsedge;fmx;fmxdae;dxSkinBlueRS25;dxTabbedMDIRS25;dxBarDBNavRS25;dxPScxPivotGridLnkRS25;dxSkinDevExpressDarkStyleRS25;dbexpress;IndyCore;dxFlowChartRS25;dxRichEditDocumentModelRS25;dsnap;DataSnapCommon;dxBarRS25;dxPSDBTeeChartRS25;dxSkinLiquidSkyRS25;dxdborRS25;DataSnapConnectors;dxPScxExtCommonRS25;cxPivotGridRS25;dxPSdxSpreadSheetLnkRS25;dxSpreadSheetReportDesignerRS25;dxNavBarRS25;cxSchedulerRibbonStyleEventEditorRS25;dxSkinCoffeeRS25;FireDACOracleDriver;DBXMySQLDriver;DBXFirebirdDriver;FireDACCommonODBC;dxSkinOffice2010SilverRS25;cxTreeListRS25;IndyIPCommon;dxSkinLondonLiquidSkyRS25;vcl;dxPScxVGridLnkRS25;dxBarExtItemsRS25;dxSkinsCoreRS25;dxComnRS25;FireDACDb2Driver;dxSkinWhiteprintRS25;dxPSdxDBTVLnkRS25;dxSkinVisualStudio2013BlueRS25;dxSkinGlassOceansRS25;dxSkinMetropolisDarkRS25;dxSkinOffice2013DarkGrayRS25;dxSkinSharpPlusRS25;TeeDB;dxSpreadSheetCoreRS25;dxServerModeRS25;dxPScxPCProdRS25;dxSkinCaramelRS25;FireDACPgDriver;ibmonitor;FireDACASADriver;cxEditorsRS25;dxSkiniMaginaryRS25;ibxpress;Tee;DataSnapServer;ibxbindings;dxPsPrVwAdvRS25;vclwinx;FireDACDSDriver;dxSkinSevenClassicRS25;cxDataRS25;dxRichEditInplaceRS25;cxTreeListdxBarPopupMenuRS25;CustomIPTransport;vcldsnap;dxPSdxOCLnkRS25;dxSkinSharpRS25;bindcomp;DBXInformixDriver;cxPivotGridChartRS25;cxSchedulerRS25;dxBarExtDBItemsRS25;dxSkinVisualStudio2013DarkRS25;dxSkinOffice2010BlackRS25;dxDBXServerModeRS25;dxSkinDevExpressStyleRS25;dxGDIPlusRS25;dxPSdxGaugeControlLnkRS25;dbxcds;unidacvcl250;adortl;dxPSdxDBOCLnkRS25;dxRibbonRS25;dsnapxml;dxSpellCheckerRS25;dbrtl;inetdbxpress;IndyProtocols;dxSkinSummer2008RS25;dxPSdxMapControlLnkRS25;dxSkinXmas2008BlueRS25;fmxase;$(DCC_UsePackage)
73 |
74 |
75 | DEBUG;$(DCC_Define)
76 | true
77 | false
78 | true
79 | true
80 | true
81 |
82 |
83 | false
84 | 1033
85 | (None)
86 |
87 |
88 | false
89 | RELEASE;$(DCC_Define)
90 | 0
91 | 0
92 |
93 |
94 |
95 | MainSource
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 | dfm
104 |
105 |
106 |
107 | Cfg_2
108 | Base
109 |
110 |
111 | Base
112 |
113 |
114 | Cfg_1
115 | Base
116 |
117 |
118 |
119 | Delphi.Personality.12
120 | Application
121 |
122 |
123 |
124 | PascalObjectSeralize.dpr
125 |
126 |
127 | Embarcadero C++Builder Office 2000 Servers Package
128 | Embarcadero C++Builder Office XP Servers Package
129 | Microsoft Office 2000 Sample Automation Server Wrapper Components
130 | Microsoft Office XP Sample Automation Server Wrapper Components
131 |
132 |
133 |
134 |
135 |
136 | PascalObjectSeralize.exe
137 | true
138 |
139 |
140 |
141 |
142 | 1
143 |
144 |
145 | Contents\MacOS
146 | 1
147 |
148 |
149 | Contents\MacOS
150 | 0
151 |
152 |
153 |
154 |
155 | classes
156 | 1
157 |
158 |
159 |
160 |
161 | library\lib\armeabi-v7a
162 | 1
163 |
164 |
165 |
166 |
167 | library\lib\armeabi
168 | 1
169 |
170 |
171 |
172 |
173 | library\lib\mips
174 | 1
175 |
176 |
177 |
178 |
179 | library\lib\armeabi-v7a
180 | 1
181 |
182 |
183 |
184 |
185 | res\drawable
186 | 1
187 |
188 |
189 |
190 |
191 | res\values
192 | 1
193 |
194 |
195 |
196 |
197 | res\drawable
198 | 1
199 |
200 |
201 |
202 |
203 | res\drawable-xxhdpi
204 | 1
205 |
206 |
207 |
208 |
209 | res\drawable-ldpi
210 | 1
211 |
212 |
213 |
214 |
215 | res\drawable-mdpi
216 | 1
217 |
218 |
219 |
220 |
221 | res\drawable-hdpi
222 | 1
223 |
224 |
225 |
226 |
227 | res\drawable-xhdpi
228 | 1
229 |
230 |
231 |
232 |
233 | res\drawable-small
234 | 1
235 |
236 |
237 |
238 |
239 | res\drawable-normal
240 | 1
241 |
242 |
243 |
244 |
245 | res\drawable-large
246 | 1
247 |
248 |
249 |
250 |
251 | res\drawable-xlarge
252 | 1
253 |
254 |
255 |
256 |
257 | 1
258 |
259 |
260 | Contents\MacOS
261 | 1
262 |
263 |
264 | 0
265 |
266 |
267 |
268 |
269 | Contents\MacOS
270 | 1
271 | .framework
272 |
273 |
274 | 0
275 |
276 |
277 |
278 |
279 | 1
280 | .dylib
281 |
282 |
283 | 1
284 | .dylib
285 |
286 |
287 | 1
288 | .dylib
289 |
290 |
291 | Contents\MacOS
292 | 1
293 | .dylib
294 |
295 |
296 | 0
297 | .dll;.bpl
298 |
299 |
300 |
301 |
302 | 1
303 | .dylib
304 |
305 |
306 | 1
307 | .dylib
308 |
309 |
310 | 1
311 | .dylib
312 |
313 |
314 | Contents\MacOS
315 | 1
316 | .dylib
317 |
318 |
319 | 0
320 | .bpl
321 |
322 |
323 |
324 |
325 | 0
326 |
327 |
328 | 0
329 |
330 |
331 | 0
332 |
333 |
334 | 0
335 |
336 |
337 | Contents\Resources\StartUp\
338 | 0
339 |
340 |
341 | 0
342 |
343 |
344 |
345 |
346 | 1
347 |
348 |
349 | 1
350 |
351 |
352 | 1
353 |
354 |
355 |
356 |
357 | 1
358 |
359 |
360 | 1
361 |
362 |
363 | 1
364 |
365 |
366 |
367 |
368 | 1
369 |
370 |
371 | 1
372 |
373 |
374 | 1
375 |
376 |
377 |
378 |
379 | 1
380 |
381 |
382 | 1
383 |
384 |
385 | 1
386 |
387 |
388 |
389 |
390 | 1
391 |
392 |
393 | 1
394 |
395 |
396 | 1
397 |
398 |
399 |
400 |
401 | 1
402 |
403 |
404 | 1
405 |
406 |
407 | 1
408 |
409 |
410 |
411 |
412 | 1
413 |
414 |
415 | 1
416 |
417 |
418 | 1
419 |
420 |
421 |
422 |
423 | 1
424 |
425 |
426 |
427 |
428 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF
429 | 1
430 |
431 |
432 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF
433 | 1
434 |
435 |
436 |
437 |
438 | 1
439 |
440 |
441 | 1
442 |
443 |
444 |
445 |
446 | ..\
447 | 1
448 |
449 |
450 | ..\
451 | 1
452 |
453 |
454 |
455 |
456 | 1
457 |
458 |
459 | 1
460 |
461 |
462 | 1
463 |
464 |
465 |
466 |
467 | 1
468 |
469 |
470 | 1
471 |
472 |
473 | 1
474 |
475 |
476 |
477 |
478 | ..\
479 | 1
480 |
481 |
482 |
483 |
484 | Contents
485 | 1
486 |
487 |
488 |
489 |
490 | Contents\Resources
491 | 1
492 |
493 |
494 |
495 |
496 | library\lib\armeabi-v7a
497 | 1
498 |
499 |
500 | 1
501 |
502 |
503 | 1
504 |
505 |
506 | 1
507 |
508 |
509 | 1
510 |
511 |
512 | Contents\MacOS
513 | 1
514 |
515 |
516 | 0
517 |
518 |
519 |
520 |
521 | 1
522 |
523 |
524 | 1
525 |
526 |
527 |
528 |
529 | Assets
530 | 1
531 |
532 |
533 | Assets
534 | 1
535 |
536 |
537 |
538 |
539 | Assets
540 | 1
541 |
542 |
543 | Assets
544 | 1
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 | False
558 | True
559 | False
560 |
561 |
562 | DUnit / Delphi Win32
563 | GUI
564 |
565 |
566 |
567 |
568 | 12
569 |
570 |
571 |
572 |
573 |
574 |
--------------------------------------------------------------------------------
/delphi_test/PascalObjectSeralize.dproj.local:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 2018/03/08 10:58:29.000.573,=E:\GitHub\PascalObjectSeralize\delphi_test\Testpascalobject_seralize.pas
5 | 2018/03/08 10:58:48.000.536,=E:\GitHub\PascalObjectSeralize\pascalobject_seralize.pas
6 | 2018/03/08 10:58:48.000.293,=E:\GitHub\PascalObjectSeralize\JsonDataObjects.pas
7 | 2018/03/08 10:58:48.000.096,=E:\GitHub\PascalObjectSeralize\intf_seralizeadapter.pas
8 | 2018/03/08 11:01:19.000.774,=E:\GitHub\PascalObjectSeralize\delphi_test\Unit1.pas
9 | 2018/03/08 11:01:31.000.644,E:\GitHub\PascalObjectSeralize\delphi_test\frm_test.pas=E:\GitHub\PascalObjectSeralize\delphi_test\Unit1.pas
10 | 2018/03/08 11:01:31.000.644,E:\GitHub\PascalObjectSeralize\delphi_test\frm_test.dfm=E:\GitHub\PascalObjectSeralize\delphi_test\Unit1.dfm
11 | 2018/03/08 11:03:24.000.533,=E:\GitHub\PascalObjectSeralize\delphi_seralizeadapter.pas
12 |
13 |
14 |
--------------------------------------------------------------------------------
/delphi_test/PascalObjectSeralize.identcache:
--------------------------------------------------------------------------------
1 | 2E:\GitHub\PascalObjectSeralize\JsonDataObjects.pas 9E:\GitHub\PascalObjectSeralize\delphi_seralizeadapter.pas 8E:\GitHub\PascalObjectSeralize\pascalobject_seralize.pas CE:\GitHub\PascalObjectSeralize\delphi_test\PascalObjectSeralize.dpr 7E:\GitHub\PascalObjectSeralize\intf_seralizeadapter.pas HE:\GitHub\PascalObjectSeralize\delphi_test\Testpascalobject_seralize.pas 7E:\GitHub\PascalObjectSeralize\delphi_test\frm_test.pas
--------------------------------------------------------------------------------
/delphi_test/PascalObjectSeralize.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ericwang1104/PascalObjectSeralize/911dcbd0a2ce84cdca8a14b0812758d0133e2ef4/delphi_test/PascalObjectSeralize.res
--------------------------------------------------------------------------------
/delphi_test/PascalObjectSeralize.skincfg:
--------------------------------------------------------------------------------
1 | [ExpressSkins]
2 | Default=1
3 | ShowNotifications=1
4 | Enabled=1
5 | dxSkinBlack=0
6 | dxSkinBlue=0
7 | dxSkinBlueprint=0
8 | dxSkinCaramel=0
9 | dxSkinCoffee=0
10 | dxSkinDarkRoom=0
11 | dxSkinDarkSide=0
12 | dxSkinDevExpressDarkStyle=0
13 | dxSkinDevExpressStyle=0
14 | dxSkinFoggy=0
15 | dxSkinGlassOceans=0
16 | dxSkinHighContrast=0
17 | dxSkiniMaginary=0
18 | dxSkinLilian=0
19 | dxSkinLiquidSky=0
20 | dxSkinLondonLiquidSky=0
21 | dxSkinMcSkin=0
22 | dxSkinMetropolis=0
23 | dxSkinMetropolisDark=0
24 | dxSkinMoneyTwins=0
25 | dxSkinOffice2007Black=0
26 | dxSkinOffice2007Blue=0
27 | dxSkinOffice2007Green=0
28 | dxSkinOffice2007Pink=0
29 | dxSkinOffice2007Silver=0
30 | dxSkinOffice2010Black=0
31 | dxSkinOffice2010Blue=0
32 | dxSkinOffice2010Silver=0
33 | dxSkinOffice2013DarkGray=0
34 | dxSkinOffice2013LightGray=0
35 | dxSkinOffice2013White=1
36 | dxSkinOffice2016Colorful=1
37 | dxSkinOffice2016Dark=1
38 | dxSkinPumpkin=0
39 | dxSkinSeven=0
40 | dxSkinSevenClassic=0
41 | dxSkinSharp=0
42 | dxSkinSharpPlus=0
43 | dxSkinSilver=0
44 | dxSkinSpringTime=0
45 | dxSkinStardust=0
46 | dxSkinSummer2008=0
47 | dxSkinTheAsphaltWorld=0
48 | dxSkinsDefaultPainters=0
49 | dxSkinValentine=0
50 | dxSkinVisualStudio2013Blue=1
51 | dxSkinVisualStudio2013Dark=1
52 | dxSkinVisualStudio2013Light=1
53 | dxSkinVS2010=0
54 | dxSkinWhiteprint=0
55 | dxSkinXmas2008Blue=0
56 |
--------------------------------------------------------------------------------
/delphi_test/PascalObjectSeralize.stat:
--------------------------------------------------------------------------------
1 | [Stats]
2 | EditorSecs=2590
3 | DesignerSecs=6
4 | InspectorSecs=14
5 | CompileSecs=21228
6 | OtherSecs=700
7 | StartTime=2018/3/8 10:06:08
8 | RealKeys=0
9 | EffectiveKeys=0
10 | DebugSecs=1
11 |
--------------------------------------------------------------------------------
/delphi_test/Testpascalobject_seralize.pas:
--------------------------------------------------------------------------------
1 | unit Testpascalobject_seralize;
2 | {
3 |
4 | Delphi DUnit Test Case
5 | ----------------------
6 | This unit contains a skeleton test case class generated by the Test Case Wizard.
7 | Modify the generated code to correctly setup and call the methods from the unit
8 | being tested.
9 |
10 | }
11 |
12 | interface
13 |
14 | uses
15 | TestFramework, pascalobject_seralize, intf_SeralizeadApter,delphi_seralizeadapter, TypInfo, Classes,
16 | SysUtils, System.NetEncoding, Variants,Dateutils, graphics,frm_test;
17 |
18 | type
19 | { TDataItem }
20 |
21 | TDataItem =Class(TcollectionItem)
22 | private
23 | FDateTime: TDateTime;
24 | fdbl: double;
25 | FInteger: integer;
26 | FStr: string;
27 | published
28 | property testInteger:integer read FInteger write FInteger;
29 | property testDate:TDateTime read FDateTime write FDateTime;
30 | property testString:string read FStr write FStr;
31 | property testFloat:double read fdbl write fdbl;
32 | end;
33 | { TDataCollection }
34 |
35 | TDataCollection=class(TCollection)
36 |
37 | private
38 | FName: string;
39 | function GetDataItem(Index: integer): TDataItem;
40 | public
41 | function AddDataItem:TDataItem;
42 | property DataItem[Index:integer]:TDataItem read GetDataItem;
43 | published
44 | property datacollectionName:string read FName write FName;
45 | end;
46 |
47 | type
48 | { TestPascalSeralize }
49 |
50 | TestPascalSeralize=class(TTestCase)
51 | protected
52 | Ffrm:TfrmTest;
53 | procedure Setup;override;
54 | procedure TearDown;override;
55 | published
56 | procedure TestGetPropInfo;
57 | end;
58 |
59 | type
60 | { TestSearalizeObject }
61 |
62 | TestSearalizeObject= class(TTestCase)
63 | private
64 | function SampleDataPath: string;
65 | protected
66 | FW:TMyCustomWriter;
67 | FR:TMyCustomReader;
68 |
69 | procedure SetUp; override;
70 | procedure TearDown; override;
71 | public
72 | published
73 | procedure TestReadfrmTest;
74 | procedure TestWritefrmTest;
75 | procedure TestWriteCollection;
76 | procedure TEstReadCollection;
77 |
78 | procedure TestWriteFrmTest_JsonAdapter;
79 | procedure TestReadFrmTest_JsonAdapter;
80 | procedure TestWriteCollection_Json;
81 | procedure TEstReadCollection_Json;
82 | end;
83 |
84 |
85 |
86 |
87 | implementation
88 |
89 | { TDataCollection }
90 |
91 | function TDataCollection.GetDataItem(Index: integer): TDataItem;
92 | begin
93 | result :=self.Items[Index] as TDataItem;
94 | end;
95 |
96 | function TDataCollection.AddDataItem: TDataItem;
97 | begin
98 | result :=TDataItem.Create(self);
99 | end;
100 |
101 | { TestPascalSeralize }
102 |
103 | procedure TestPascalSeralize.Setup;
104 | begin
105 | inherited ;
106 | fFrm :=TfrmTest.Create(nil);
107 | end;
108 |
109 | procedure TestPascalSeralize.TearDown;
110 | begin
111 | FreeAndNil(fFrm);
112 | inherited ;
113 | end;
114 |
115 | procedure TestPascalSeralize.TestGetPropInfo;
116 | var
117 | I: Integer;
118 | PList: PPropList;
119 | intPropCount: Integer;
120 | PInfo: PPropInfo;
121 | begin
122 |
123 |
124 | // Save Collection
125 | intPropCount := GetTypeData(ffrm.ClassInfo)^.PropCount;
126 | GetMem(PList, intPropCount * SizeOf(Pointer));
127 | try
128 | intPropCount := GetPropList(ffrm.ClassInfo, tkAny, PList);
129 | for I := 0 to intPropCount-1 do
130 | begin
131 | PInfo :=PList^[I];
132 |
133 | {$IFDEF DEBUG}
134 |
135 |
136 | //SendInteger('Prop Index:',Pinfo^.PropProcs);
137 | //SendDebug('PropName:'+Pinfo^.Name);
138 | {$ENDIF}
139 | end;
140 |
141 | finally
142 | FreeMem(PList, intPropCount * SizeOf(Pointer));
143 | end;
144 |
145 |
146 | end;
147 |
148 | function TestSearalizeObject.SampleDataPath: string;
149 | begin
150 | result :='..\..\..\testdata\';
151 | end;
152 |
153 | procedure TestSearalizeObject.TestWritefrmTest;
154 | var
155 | Iadp:IDataAdapter;
156 | frm:TfrmTest;
157 | begin
158 | iadp :=TDJsonAdapter.Create;
159 | frm :=TfrmTest.Create(nil);
160 | try
161 | fW.Adapter :=Iadp;
162 | frm.Image1.Picture.LoadFromFile(SampleDataPath+'test.png');
163 | frm.ShowModal;
164 | fw.WriteObjectToFile(SampleDataPath+'test.xml',frm);
165 | finally
166 | FreeAndnil(frm);
167 | end;
168 |
169 | end;
170 |
171 | procedure TestSearalizeObject.TestWriteCollection;
172 | var
173 | coll:TDataCollection;
174 | Item:TDataItem;
175 | IAdp:TDJsonAdapter;
176 | begin
177 | Coll :=TDatacollection.Create(TdataItem);
178 | IAdp :=TDJsonAdapter.Create;
179 | try
180 | Coll.datacollectionName:='TestDataName';
181 |
182 | Item :=coll.AddDataItem;
183 | item.testDate:=now;
184 | item.testFloat:=3.14;
185 | item.testInteger:=28;
186 | item.testString:='hello world';
187 | fw.Adapter :=IAdp;
188 | fw.WriteObjectToFile(SampleDataPath+'testCollection.xml',Coll);
189 |
190 | finally
191 | FreeAndNil( Coll);
192 | end;
193 | end;
194 |
195 | procedure TestSearalizeObject.TEstReadCollection;
196 | var
197 | coll:TDataCollection;
198 | Item:TDataItem;
199 | IAdp:TDJsonAdapter;
200 | begin
201 | Coll :=TDatacollection.Create(TdataItem);
202 | IAdp :=TDJsonAdapter.Create;
203 | try
204 | fr.Adapter :=IAdp;
205 | fr.ReadFileToObject(SampleDataPath+'testcollection.xml',coll);
206 | checkequals(Coll.datacollectionName,'TestDataName');
207 | Item :=Coll.DataItem[0];
208 |
209 | checkequals(item.testString,'hello world');
210 | checkequals(item.testInteger,28);
211 | checkequals(item.testFloat,3.14);
212 | checkequals(YearOf(item.testDate),yearOf(now));
213 |
214 | finally
215 | FreeAndNil( Coll);
216 | end;
217 |
218 | end;
219 |
220 | procedure TestSearalizeObject.TestWriteFrmTest_JsonAdapter;
221 | var
222 | Iadp:IDataAdapter;
223 | frm:TfrmTest;
224 | begin
225 | iadp :=TDJsonAdapter.Create;
226 | frm :=TfrmTest.Create(nil);
227 | try
228 | fW.Adapter :=Iadp;
229 | // frm.Image1.Picture.LoadFromFile('E:\GitHub\PascalObjectSeralize\testdata\'+'test.png');
230 | frm.ShowModal;
231 | fw.WriteObjectToFile(SampleDataPath+'test.json',frm);
232 | finally
233 | FreeAndnil(frm);
234 | end;
235 | end;
236 |
237 | procedure TestSearalizeObject.TestReadFrmTest_JsonAdapter;
238 | var
239 | Iadp:IDataAdapter;
240 | frm:TfrmTest;
241 | begin
242 | iadp :=TDJsonAdapter.Create;
243 | frm :=TfrmTest.Create(nil);
244 | try
245 | fr.Adapter :=Iadp;
246 | fr.ReadFileToObject(SampleDataPath+'test.json',frm) ;
247 | frm.ShowModal;
248 | finally
249 | FreeAndnil(frm);
250 | end;
251 |
252 |
253 | end;
254 |
255 | procedure TestSearalizeObject.TestWriteCollection_Json;
256 | var
257 | coll:TDataCollection;
258 | Item:TDataItem;
259 | IAdp:IDataAdapter;
260 | begin
261 | Coll :=TDatacollection.Create(TdataItem);
262 | IAdp :=TDJsonAdapter.Create;
263 | try
264 | Coll.datacollectionName:='TestDataName';
265 |
266 | Item :=coll.AddDataItem;
267 | item.testDate:=now;
268 | item.testFloat:=3.14;
269 | item.testInteger:=28;
270 | item.testString:='hello world';
271 |
272 |
273 | Item :=coll.AddDataItem;
274 | Item.testDate :=Date;
275 | item.testFloat :=2.2;
276 | item.testInteger :=9;
277 | item.testString :='delphi test';
278 |
279 | fw.Adapter :=IAdp;
280 |
281 | fw.WriteObjectToFile(SampleDataPath+'testCollection.Json',Coll);
282 |
283 | finally
284 | FreeAndNil( Coll);
285 | end;
286 |
287 | end;
288 |
289 | procedure TestSearalizeObject.TEstReadCollection_Json;
290 | var
291 | coll:TDataCollection;
292 | Item:TDataItem;
293 | IAdp:IDataAdapter;
294 | begin
295 | Coll :=TDatacollection.Create(TdataItem);
296 | IAdp :=TDJsonAdapter.Create;
297 | try
298 | fr.Adapter :=IAdp;
299 | fr.ReadFileToObject(SampleDataPath+'testcollection.Json',coll);
300 | checkequals(Coll.datacollectionName,'TestDataName');
301 | Item :=Coll.DataItem[0];
302 |
303 | checkequals(item.testString,'hello world');
304 | checkequals(item.testInteger,28);
305 | CheckTrue(abs(item.testFloat-3.14)<=0.0000001,'float not equals');
306 | checkequals(YearOf(item.testDate),yearOf(now));
307 |
308 | finally
309 | FreeAndNil( Coll);
310 | end;
311 |
312 | end;
313 |
314 | procedure TestSearalizeObject.SetUp;
315 | begin
316 | FW :=TMyCustomWriter.Create(nil);
317 | Fr :=TMyCustomReader.Create(nil);
318 | end;
319 |
320 | procedure TestSearalizeObject.TearDown;
321 | begin
322 | FreeAndnil(Fr);
323 | FreeAndNil(FW);
324 | end;
325 |
326 | procedure TestSearalizeObject.TestReadfrmTest;
327 | var
328 | Iadp:IDataAdapter;
329 | frm:TfrmTest;
330 | begin
331 | iadp :=TDJsonAdapter.Create;
332 | frm :=TfrmTest.Create(nil);
333 | try
334 | fr.Adapter :=Iadp;
335 | fr.ReadFileToObject(SampleDataPath+'test.xml',frm) ;
336 | frm.ShowModal;
337 | finally
338 | FreeAndnil(frm);
339 | end;
340 |
341 |
342 | end;
343 |
344 | initialization
345 | // Register any test cases with the test runner
346 | registerTest(TestPascalSeralize.suite);
347 | RegisterTest(TestSearalizeObject.suite);
348 | RegisterClass(TDataItem);
349 | RegisterClass(TDataCollection);
350 | end.
351 |
352 |
--------------------------------------------------------------------------------
/delphi_test/frm_test.dfm:
--------------------------------------------------------------------------------
1 | object frmTest: TfrmTest
2 | Left = 0
3 | Top = 0
4 | Caption = 'frmTest'
5 | ClientHeight = 231
6 | ClientWidth = 505
7 | Color = clBtnFace
8 | Font.Charset = DEFAULT_CHARSET
9 | Font.Color = clWindowText
10 | Font.Height = -11
11 | Font.Name = 'Tahoma'
12 | Font.Style = []
13 | OldCreateOrder = False
14 | PixelsPerInch = 96
15 | TextHeight = 13
16 | object Image1: TImage
17 | Left = 328
18 | Top = 48
19 | Width = 105
20 | Height = 105
21 | end
22 | object Edit1: TEdit
23 | Left = 24
24 | Top = 24
25 | Width = 121
26 | Height = 21
27 | TabOrder = 0
28 | Text = 'aaaaaaaaaaa'
29 | end
30 | object Memo1: TMemo
31 | Left = 40
32 | Top = 112
33 | Width = 185
34 | Height = 89
35 | TabOrder = 1
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/delphi_test/frm_test.pas:
--------------------------------------------------------------------------------
1 | unit frm_test;
2 |
3 | interface
4 |
5 | uses
6 | Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
7 | Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, dxGDIPlusClasses,
8 | Vcl.StdCtrls;
9 |
10 | type
11 | TfrmTest = class(TForm)
12 | Image1: TImage;
13 | Edit1: TEdit;
14 | Memo1: TMemo;
15 | private
16 | { Private declarations }
17 | public
18 | { Public declarations }
19 | end;
20 |
21 | var
22 | frmTest: TfrmTest;
23 |
24 | implementation
25 |
26 | {$R *.dfm}
27 |
28 | end.
29 |
--------------------------------------------------------------------------------
/delphi_test/testPascalObjectSeralize.dpr:
--------------------------------------------------------------------------------
1 | program testPascalObjectSeralize;
2 | {
3 |
4 | Delphi DUnit Test Project
5 | -------------------------
6 | This project contains the DUnit test framework and the GUI/Console test runners.
7 | Add "CONSOLE_TESTRUNNER" to the conditional defines entry in the project options
8 | to use the console test runner. Otherwise the GUI test runner will be used by
9 | default.
10 |
11 | }
12 |
13 | {$IFDEF CONSOLE_TESTRUNNER}
14 | {$APPTYPE CONSOLE}
15 | {$ENDIF}
16 |
17 | uses
18 | DUnitTestRunner,
19 | Testpascalobject_seralize in 'Testpascalobject_seralize.pas',
20 | intf_seralizeadapter in '..\intf_seralizeadapter.pas',
21 | JsonDataObjects in '..\JsonDataObjects.pas',
22 | pascalobject_seralize in '..\pascalobject_seralize.pas',
23 | frm_test in 'frm_test.pas' {frmTest},
24 | delphi_seralizeadapter in '..\delphi_seralizeadapter.pas';
25 |
26 | {$R *.RES}
27 |
28 | begin
29 | {$IFDEF DEBUG}
30 | ReportMemoryLeaksOnShutdown :=true;
31 | {$ENDIF}
32 | DUnitTestRunner.RunRegisteredTests;
33 | end.
34 |
35 |
--------------------------------------------------------------------------------
/delphi_test/testPascalObjectSeralize.dproj.local:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 2018/03/08 10:58:29.000.573,=E:\GitHub\PascalObjectSeralize\delphi_test\Testpascalobject_seralize.pas
5 | 2018/03/08 10:58:48.000.536,=E:\GitHub\PascalObjectSeralize\pascalobject_seralize.pas
6 | 2018/03/08 10:58:48.000.293,=E:\GitHub\PascalObjectSeralize\JsonDataObjects.pas
7 | 2018/03/08 10:58:48.000.096,=E:\GitHub\PascalObjectSeralize\intf_seralizeadapter.pas
8 | 2018/03/08 11:01:19.000.774,=E:\GitHub\PascalObjectSeralize\delphi_test\Unit1.pas
9 | 2018/03/08 11:01:31.000.644,E:\GitHub\PascalObjectSeralize\delphi_test\frm_test.pas=E:\GitHub\PascalObjectSeralize\delphi_test\Unit1.pas
10 | 2018/03/08 11:01:31.000.644,E:\GitHub\PascalObjectSeralize\delphi_test\frm_test.dfm=E:\GitHub\PascalObjectSeralize\delphi_test\Unit1.dfm
11 | 2018/03/08 11:03:24.000.533,=E:\GitHub\PascalObjectSeralize\delphi_seralizeadapter.pas
12 | 2018/03/09 07:50:25.000.553,E:\GitHub\PascalObjectSeralize\delphi_test\PascalObjectSeralize.dproj=E:\GitHub\PascalObjectSeralize\delphi_test\testPascalObjectSeralize.dproj
13 | 2018/03/11 10:37:45.000.974,=E:\GitHub\PascalObjectSeralize\fpc_seralizeadapter.pas
14 | 2018/03/11 10:47:00.000.178,E:\GitHub\PascalObjectSeralize\fpc_seralizeadapter.pas=
15 |
16 |
17 |
--------------------------------------------------------------------------------
/delphi_test/testPascalObjectSeralize.identcache:
--------------------------------------------------------------------------------
1 | HE:\GitHub\PascalObjectSeralize\delphi_test\Testpascalobject_seralize.pas GE:\GitHub\PascalObjectSeralize\delphi_test\testPascalObjectSeralize.dpr 8E:\GitHub\PascalObjectSeralize\pascalobject_seralize.pas 7E:\GitHub\PascalObjectSeralize\intf_seralizeadapter.pas 9E:\GitHub\PascalObjectSeralize\delphi_seralizeadapter.pas 7E:\GitHub\PascalObjectSeralize\delphi_test\frm_test.pas 2E:\GitHub\PascalObjectSeralize\JsonDataObjects.pas
--------------------------------------------------------------------------------
/delphi_test/testPascalObjectSeralize.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ericwang1104/PascalObjectSeralize/911dcbd0a2ce84cdca8a14b0812758d0133e2ef4/delphi_test/testPascalObjectSeralize.res
--------------------------------------------------------------------------------
/delphi_test/testPascalObjectSeralize.skincfg:
--------------------------------------------------------------------------------
1 | [ExpressSkins]
2 | Default=1
3 | ShowNotifications=1
4 | Enabled=1
5 | dxSkinBlack=0
6 | dxSkinBlue=0
7 | dxSkinBlueprint=0
8 | dxSkinCaramel=0
9 | dxSkinCoffee=0
10 | dxSkinDarkRoom=0
11 | dxSkinDarkSide=0
12 | dxSkinDevExpressDarkStyle=0
13 | dxSkinDevExpressStyle=0
14 | dxSkinFoggy=0
15 | dxSkinGlassOceans=0
16 | dxSkinHighContrast=0
17 | dxSkiniMaginary=0
18 | dxSkinLilian=0
19 | dxSkinLiquidSky=0
20 | dxSkinLondonLiquidSky=0
21 | dxSkinMcSkin=0
22 | dxSkinMetropolis=0
23 | dxSkinMetropolisDark=0
24 | dxSkinMoneyTwins=0
25 | dxSkinOffice2007Black=0
26 | dxSkinOffice2007Blue=0
27 | dxSkinOffice2007Green=0
28 | dxSkinOffice2007Pink=0
29 | dxSkinOffice2007Silver=0
30 | dxSkinOffice2010Black=0
31 | dxSkinOffice2010Blue=0
32 | dxSkinOffice2010Silver=0
33 | dxSkinOffice2013DarkGray=0
34 | dxSkinOffice2013LightGray=0
35 | dxSkinOffice2013White=1
36 | dxSkinOffice2016Colorful=1
37 | dxSkinOffice2016Dark=1
38 | dxSkinPumpkin=0
39 | dxSkinSeven=0
40 | dxSkinSevenClassic=0
41 | dxSkinSharp=0
42 | dxSkinSharpPlus=0
43 | dxSkinSilver=0
44 | dxSkinSpringTime=0
45 | dxSkinStardust=0
46 | dxSkinSummer2008=0
47 | dxSkinTheAsphaltWorld=0
48 | dxSkinsDefaultPainters=0
49 | dxSkinValentine=0
50 | dxSkinVisualStudio2013Blue=1
51 | dxSkinVisualStudio2013Dark=1
52 | dxSkinVisualStudio2013Light=1
53 | dxSkinVS2010=0
54 | dxSkinWhiteprint=0
55 | dxSkinXmas2008Blue=0
56 |
--------------------------------------------------------------------------------
/delphi_test/testPascalObjectSeralize.stat:
--------------------------------------------------------------------------------
1 | [Stats]
2 | EditorSecs=5335
3 | DesignerSecs=75
4 | InspectorSecs=98
5 | CompileSecs=141482
6 | OtherSecs=1581
7 | StartTime=2018/3/9 8:57:54
8 | RealKeys=0
9 | EffectiveKeys=0
10 | DebugSecs=2616
11 |
--------------------------------------------------------------------------------
/fpc_seralizeadapter.pas:
--------------------------------------------------------------------------------
1 | unit fpc_seralizeadapter;
2 | {$mode objfpc}{$H+}
3 | interface
4 |
5 | uses
6 | Classes, SysUtils, variants,
7 | fpjson, dbugintf,Laz_XMLRead, Laz2_DOM, Laz_XMLWrite,
8 | intf_seralizeadapter;
9 | type
10 |
11 | { TFPCXmlNode }
12 | TFPCXmlNode=class(TInterfacedObject,IDataNode)
13 |
14 |
15 | function GetAttributes(Name: string): string;
16 | function GetChildItem(Index:integer): IDataNode;
17 | function GetNodeName: string;
18 | function GetValue: variant;
19 | procedure SetAttributes(Name: string; AValue: string);
20 | procedure SetNodeName(AValue: string);
21 | procedure SetValue(AValue: variant);
22 | function AddChild():IDataNode;
23 | function ChildCount:integer;
24 | procedure SetData(AValue: string);
25 | function AddPropObj(const Name: string): IDataNode;
26 | function PropObjByName(const Name:string): IDataNode;
27 | function GetData: string;
28 | function GetDumpText:string;
29 | protected
30 | fDoc:TDOMDocument;
31 | fNode:TDOMNode;
32 | function BuilDataNode(const Node:TDOMNode):IDataNode;
33 | end;
34 | {TFPCJsonNode=class(TInterfacedObject,IDataNode)
35 |
36 | end;}
37 |
38 |
39 | { TFPCXmlAdapter }
40 |
41 | TFPCXmlAdapter=class(TInterfacedObject,IDataAdapter)
42 |
43 |
44 |
45 | function NewDoc:IDataNode;
46 | function GetRootNode:IDataNode;
47 | procedure LoadFromFile(const Filename:string);
48 | procedure SaveToFile(const FileName:string);
49 | function GetSeralzieString: string;
50 | private
51 | fDoc:TXMLDocument;
52 | public
53 | destructor Destroy;override;
54 |
55 | end;
56 | TFPCJsonNode=class(TInterfacedObject,IDataNode)
57 | function GetAttributes(Name: string): string;
58 | function GetChildItem(Index:integer): IDataNode;
59 | function GetNodeName: string;
60 | function GetValue: variant;
61 | procedure SetAttributes(Name: string; AValue: string);
62 | procedure SetNodeName(AValue: string);
63 | procedure SetValue(AValue: variant);
64 | function AddChild():IDataNode;
65 | function ChildCount:integer;
66 | procedure SetData(AValue: string);
67 | function GetData: string;
68 | function AddPropObj(const Name: string): IDataNode;
69 | function PropObjByName(const Name:string): IDataNode;
70 | function GetDumpText:string;
71 | protected
72 | fDoc:TJsonObject;
73 | fNode:TJSOnData;
74 | FParent:TJsonObject;
75 | function BuilDataNode(const Node:TJsonData):IDataNode;
76 | end;
77 |
78 | { TFPCJsonAdapter }
79 |
80 | TFPCJsonAdapter=class(TInterfacedObject,IDataAdapter)
81 | function NewDoc:IDataNode;
82 | function GetRootNode:IDataNode;
83 | procedure LoadFromFile(const Filename:string);
84 | procedure SaveToFile(const FileName:string);
85 | function GetSeralzieString: string;
86 | private
87 | fDoc:TJsonObject;
88 | public
89 | destructor Destroy;override;
90 | end;
91 | implementation
92 |
93 | { TFPCJsonNode }
94 |
95 | function TFPCJsonNode.GetAttributes(Name: string): string;
96 | begin
97 | if FNode is TJSonData then
98 | begin
99 | result :=(FNode as TJsonObject).Get(LowerCase(Name));
100 | end else
101 | begin
102 | assert(false,'fnode is not a object');
103 | end;
104 | end;
105 |
106 | function TFPCJsonNode.GetChildItem(Index: integer): IDataNode;
107 | var
108 | Item:TJsonObject;
109 | Count:integer;
110 | JObj:TJsonObject;
111 | Arr:TJSONArray;
112 | begin
113 | JObj :=FNode as TJsonObject;
114 | Arr :=JObj.Arrays['ITEMS'];
115 | Item :=Arr.Objects[Index];
116 | result :=BuilDataNode(Item);
117 | end;
118 |
119 | function TFPCJsonNode.GetNodeName: string;
120 | var
121 | Index:integer;
122 | begin
123 | Index :=FParent.IndexOf(FNode);
124 | result :=FParent.Names[Index];
125 |
126 | end;
127 |
128 | function TFPCJsonNode.GetValue: variant;
129 | begin
130 | result :=FNode.Value;
131 | end;
132 |
133 | procedure TFPCJsonNode.SetAttributes(Name: string; AValue: string);
134 | var
135 | JD:TJSOnData;
136 | Jobj:TJsonObject;
137 | begin
138 | if FNode is TJsonObject then
139 | begin
140 | JObj :=FNode as TJsonObject;
141 | JD :=Jobj.Find(LowerCase(Name));
142 | if not Assigned(JD)then
143 | begin
144 | (FNode as TJsonObject).Add(LowerCase(Name),AValue);
145 | end else
146 | begin
147 | jd.AsString:=AValue;
148 | end;
149 | end;
150 | end;
151 |
152 | procedure TFPCJsonNode.SetNodeName(AValue: string);
153 | begin
154 | (FNode as TJsonObject).Find('name').Value :=AVAlue;
155 | end;
156 |
157 | procedure TFPCJsonNode.SetValue(AValue: variant);
158 |
159 | begin
160 | FNode.Value:=AValue;
161 |
162 | end;
163 |
164 | function TFPCJsonNode.AddChild(): IDataNode;
165 | var
166 | JObj:TJsonObject;
167 | Child:TJsonObject;
168 | JNode:TFPCJsonNode;
169 | JArr:TJSONArray;
170 | begin
171 | JObj :=FNode as TJsonObject;
172 | if not JObj.Find('ITEMS',JArr) then
173 | begin
174 | JArr :=TJSONArray.Create;
175 | JObj.Add('ITEMS',JArr);
176 | end;
177 |
178 | Child :=TJsonObject.Create();
179 | JArr.Add(Child);
180 | result :=BuilDataNode(Child);
181 | end;
182 |
183 | function TFPCJsonNode.ChildCount: integer;
184 | var
185 | JObj:TJsonObject;
186 | Arr:TJSONArray;
187 | begin
188 | JObj :=fNode as TJsonObject;
189 | Arr :=Jobj.Arrays['ITEMS'];
190 | result :=Arr.Count;
191 | end;
192 |
193 |
194 |
195 | procedure TFPCJsonNode.SetData(AValue: string);
196 | begin
197 | (FNode as TJSonObject).Add('cdata',AValue);
198 | end;
199 |
200 | function TFPCJsonNode.GetData: string;
201 | begin
202 | result :=(FNode as TJsonObject).Get('cdata');
203 | end;
204 |
205 | function TFPCJsonNode.AddPropObj(const Name: string): IDataNode;
206 | var
207 | JObj,Child:TJsonObject;
208 | begin
209 |
210 | JObj :=FNode as TJsonObject;
211 | Child :=TJsonObject.Create;
212 | Jobj.Add(Name,Child);
213 | Result :=self.BuilDataNode(child);
214 |
215 | end;
216 |
217 | function TFPCJsonNode.PropObjByName(const Name: string): IDataNode;
218 | var
219 | JObj,PropObj :TJsonObject;
220 | begin
221 | JObj :=FNode as TJsonObject;
222 | if JObj.Find(LowerCase(Name),PropObj) then
223 | begin
224 | result :=BuilDataNode(PropObj);
225 | end else
226 | begin
227 | result :=nil;
228 | end;
229 | end;
230 |
231 | function TFPCJsonNode.GetDumpText: string;
232 | begin
233 | result :=FNode.AsJSON;
234 | end;
235 |
236 |
237 |
238 |
239 |
240 | function TFPCJsonNode.BuilDataNode(const Node: TJsonData): IDataNode;
241 | var
242 | JNode:TFPCJsonNode;
243 | begin
244 | JNode :=TFPCJsonNode.Create;
245 | JNode.fDoc :=self.fDoc;
246 | JNode.fNode :=Node;
247 | JNode.FParent :=FNode as TJsonObject;
248 | result :=JNode;
249 | end;
250 |
251 | { TFPCJsonAdapter }
252 |
253 | function TFPCJsonAdapter.NewDoc: IDataNode;
254 | begin
255 | Fdoc :=GetJson('{JSONOBJECT:{}}') as TJsonObject;
256 | end;
257 |
258 | function TFPCJsonAdapter.GetRootNode: IDataNode;
259 | var
260 | Node:TFPCJsonNode;
261 | JObj:TJsonObject;
262 | begin
263 | JObj :=FDoc.Find('JSONOBJECT') as TJsonObject;
264 | Node :=TFPCJsonNode.Create;
265 | Node.fNode :=JObj;
266 | Node.FParent :=FDoc;
267 | Node.fDoc :=fDOc;
268 | result :=Node;
269 | end;
270 |
271 | procedure TFPCJsonAdapter.LoadFromFile(const Filename: string);
272 | var
273 | FS:TFileStream;
274 | begin
275 | FS :=TFileStream.Create(FileName,fmopenRead);
276 | try
277 | FS.Position:=0;
278 | if not Assigned(Fdoc) then FreeAndNil(FDoc);
279 | FDoc :=GetJson(FS) as TJsonObject;
280 | finally
281 | FreeAndNil(FS);
282 | end;
283 | end;
284 |
285 | procedure TFPCJsonAdapter.SaveToFile(const FileName: string);
286 | var
287 | FS:TFileStream;
288 | begin
289 | FS :=TFileStream.Create(FileName,fmcreate);
290 | try
291 | //FDoc.FormatJSON([foUseTabchar,foSkipWhiteSpace]);
292 | FDoc.FormatJSON(DefaultFormat);
293 | Fdoc.DumpJSON(FS);
294 |
295 | finally
296 | FreeAndNil(FS);
297 | end;
298 | end;
299 |
300 | function TFPCJsonAdapter.GetSeralzieString: string;
301 | begin
302 | result :=fdoc.AsString;
303 | end;
304 |
305 | destructor TFPCJsonAdapter.Destroy;
306 | begin
307 | if Assigned(FDoc) then
308 | FreeAndNil(FDoc);
309 | inherited ;
310 | end;
311 |
312 | { TFPCXmlNode }
313 |
314 | function TFPCXmlNode.BuilDataNode(const Node: TDOMNode): IDataNode;
315 | var
316 | xmlNode:TFPCXmlNode;
317 | begin
318 | xmlNode :=TFpcXmlNode.Create;
319 | xmlNode.fDoc :=self.fDoc;
320 | xmlnode.fNode :=Node;
321 | result :=xmlNode;
322 |
323 | end;
324 |
325 | function TFPCXmlNode.GetAttributes(Name: string): string;
326 | begin
327 | result :=fNode.Attributes.GetNamedItem(Name).NodeValue;
328 | end;
329 |
330 | function TFPCXmlNode.GetChildItem(Index: integer): IDataNode;
331 | var
332 | Node:TDOMNode;
333 | begin
334 | //result :=fNode.ChildNodes[Index];
335 | Node :=fNode.ChildNodes[Index];
336 | result :=self.BuilDataNode(Node);
337 | end;
338 |
339 | function TFPCXmlNode.GetNodeName: string;
340 | begin
341 | result :=fNode.NodeName;
342 | end;
343 |
344 | function TFPCXmlNode.GetValue: variant;
345 | begin
346 | result :=fNode.NodeValue;
347 | end;
348 |
349 | procedure TFPCXmlNode.SetAttributes(Name: string; AValue: string);
350 | var
351 | attr:TDOMNode;
352 | begin
353 | attr :=FNode.Attributes.GetNamedItem(Name);
354 | if Assigned(Attr) then
355 | begin
356 | attr.NodeValue:=AValue;
357 | end else
358 | begin
359 | if fNode is TDOMElement then
360 | begin
361 | (fNode as TDOMElement).SetAttribute(Name,AValue);
362 | end else
363 | begin
364 | assert(false,'this nod is not a element node');
365 | end;
366 | end;
367 | end;
368 |
369 | procedure TFPCXmlNode.SetNodeName(AValue: string);
370 | begin
371 | //
372 | end;
373 |
374 | procedure TFPCXmlNode.SetValue(AValue: variant);
375 | begin
376 | fNode.NodeValue :=VarTostr(AValue);
377 | end;
378 |
379 |
380 |
381 |
382 | function TFPCXmlNode.AddChild(): IDataNode;
383 | var
384 | Ele:TDomElement;
385 | begin
386 | Ele :=FDoc.CreateElement('ITEM');
387 | fNode.AppendChild(Ele);
388 | result :=self.BuilDataNode(Ele);
389 | end;
390 |
391 | function TFPCXmlNode.ChildCount: integer;
392 | begin
393 | result :=FNode.ChildNodes.Count;
394 | end;
395 |
396 |
397 |
398 | procedure TFPCXmlNode.SetData(AValue: string);
399 | var
400 | xmlNode :TFPCXmlNode;
401 | CData:TDOMCDataSection;
402 | begin
403 | CData :=fDoc.CreateCDATASection(AVAlue);
404 | fNode.AppendChild(CData);
405 |
406 |
407 | end;
408 |
409 | function TFPCXmlNode.AddPropObj(const Name: string): IDataNode;
410 | var
411 | Ele:TDOMElement;
412 | begin
413 | Ele :=FDoc.CreateElement(Name);
414 | FNode.AppendChild(Ele);
415 | Result :=self.BuilDataNode(Ele);
416 |
417 | end;
418 |
419 | function TFPCXmlNode.PropObjByName(const Name: string): IDataNode;
420 | var
421 | Node:TDOMNode;
422 | begin
423 | {JObj :=FJSon.O[Name];
424 | if Assigned(JObj) then
425 | begin
426 | result :=BuildDataNode(JObj)
427 | end else
428 | begin
429 | result :=nil;
430 | end; }
431 | Node :=FDoc.FindNode(Name);
432 | if Assigned(Node) then
433 | begin
434 | result :=self.BuilDataNode(Node);
435 | end else
436 | begin
437 | result :=nil;
438 | end;
439 | end;
440 |
441 | function TFPCXmlNode.GetData: string;
442 | begin
443 | result :=FNode.FindNode('#cdata-section').NodeValue;
444 | end;
445 |
446 | function TFPCXmlNode.GetDumpText: string;
447 | begin
448 | result :=self.fNode.TextContent;
449 | end;
450 |
451 |
452 |
453 | { TFPCXmlAdapter }
454 |
455 | destructor TFPCXmlAdapter.Destroy;
456 | begin
457 | if Assigned(fDoc) then
458 | FreeAndNil(fDoc);
459 | inherited ;
460 | end;
461 |
462 | function TFPCXmlAdapter.NewDoc: IDataNode;
463 | var
464 | Element:TDomElement;
465 | begin
466 | if Assigned(fDoc) then
467 | begin
468 | FreeAndNil(fDoc);
469 | end;
470 | fDoc :=TXMLDocument.Create;
471 | Element :=fdoc.CreateElement('XMLObject');
472 | Fdoc.AppendChild(Element);
473 | end;
474 |
475 | function TFPCXmlAdapter.GetRootNode: IDataNode;
476 | var
477 | xmlNode:TFPCXmlNode;
478 | begin
479 | xmlNode :=TFPCXmlNode.Create;
480 | xmlNode.fNode :=fDoc.FirstChild;
481 | xmlNode.fDoc :=fDoc;
482 | result :=xmlNode;
483 | end;
484 |
485 | procedure TFPCXmlAdapter.LoadFromFile(const Filename: string);
486 | begin
487 | //
488 | ReadXMLFile(fDoc,FileName);
489 | end;
490 |
491 | procedure TFPCXmlAdapter.SaveToFile(const FileName: string);
492 | begin
493 |
494 | WriteXML(fDoc,FileName);
495 | end;
496 |
497 | function TFPCXmlAdapter.GetSeralzieString: string;
498 | begin
499 | WriteXML(FDoc,result);
500 | end;
501 |
502 |
503 |
504 | end.
505 |
506 |
--------------------------------------------------------------------------------
/intf_seralizeadapter.pas:
--------------------------------------------------------------------------------
1 | unit intf_seralizeadapter;
2 | {$IFDEF PFC}
3 | {$mode objfpc}{$H+}
4 | {$ENDIF}
5 | interface
6 |
7 | uses
8 | Classes, SysUtils;
9 | const
10 | DATA_NODE_INTERFACE='{33427852-44EE-4EA8-A339-29C082DF3499}';
11 | Data_ADAPTER_INTERFACE='{69CFA652-6127-45FC-934E-FD48871E33DF}';
12 | type
13 | { TDataNode }
14 |
15 | { IDataNode }
16 |
17 | IDataNode=Interface(IInterface)
18 | [DATA_NODE_INTERFACE]
19 | function GetAttributes(Name: string): string;
20 | function GetChildItem(Index:integer): IDataNode;
21 | function GetDumpText: string;
22 | function GetNodeName: string;
23 | function GetValue: variant;
24 | procedure SetAttributes(Name: string; AValue: string);
25 | procedure SetNodeName(AValue: string);
26 | procedure SetValue(AValue: variant);
27 | function AddChild():IDataNode;
28 | function AddPropObj(const Name: string): IDataNode;
29 | function ChildCount:integer;
30 | function PropObjByName(const Name:string): IDataNode;
31 | procedure SetData(AValue: string);
32 | function GetData: string;
33 |
34 | Property ChildItem[Index:integer]:IDataNode read GetChildItem;
35 | Property DATA:string read GetData write SetData;
36 | property NodeName:string read GetNodeName write SetNodeName;
37 | property Value:variant read GetValue write SetValue;
38 | property Attributes[Name:string]:string read GetAttributes write SetAttributes;
39 | property DumpText:string read GetDumpText;
40 | end;
41 |
42 | { IDataAdapter }
43 |
44 | IDataAdapter=interface(IInterface)
45 | [Data_ADAPTER_INTERFACE]
46 | function NewDoc:IDataNode;
47 | function GetRootNode: IDataNode;
48 | function GetSeralzieString: string;
49 | procedure LoadFromFile(const FileName:string);
50 | procedure SaveToFile(const FileName:string);
51 | property RootNode:IDataNode read GetRootNode;
52 | end;
53 |
54 |
55 |
56 | implementation
57 |
58 |
59 |
60 | { TDataNode }
61 |
62 |
63 |
64 | end.
65 |
66 |
--------------------------------------------------------------------------------
/pascalobject_seralize.pas:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ericwang1104/PascalObjectSeralize/911dcbd0a2ce84cdca8a14b0812758d0133e2ef4/pascalobject_seralize.pas
--------------------------------------------------------------------------------
/test/backup/frm_test.lfm:
--------------------------------------------------------------------------------
1 | object frmTest: TfrmTest
2 | Left = 389
3 | Height = 373
4 | Top = 137
5 | Width = 427
6 | AllowDropFiles = True
7 | Caption = 'Action1'
8 | ClientHeight = 373
9 | ClientWidth = 427
10 | OnCreate = FormCreate
11 | LCLVersion = '1.6.4.0'
12 | object Image1: TImage
13 | Left = 16
14 | Height = 178
15 | Top = 24
16 | Width = 322
17 | end
18 | object Button1: TButton
19 | Left = 16
20 | Height = 25
21 | Top = 232
22 | Width = 75
23 | Action = actTest
24 | TabOrder = 0
25 | end
26 | object ActionList1: TActionList
27 | left = 335
28 | top = 233
29 | object actTest: TAction
30 | Caption = 'Action1'
31 | OnExecute = actTestExecute
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/test/backup/pascalobject_seralize_test.lpi:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/test/backup/pascalobject_seralize_test.lpr:
--------------------------------------------------------------------------------
1 | program pascalobject_seralize_test;
2 |
3 | {$mode objfpc}{$H+}
4 | uses
5 | Interfaces, Forms,GuiTestRunner, testfpc_seralizeadapter_test,
6 | test_pascalobjectseralize, frm_Test;
7 |
8 | {$R *.res}
9 |
10 | begin
11 | Application.Initialize;
12 | Application.CreateForm(TGuiTestRunner, TestRunner);
13 | Application.CreateForm(TfrmTest, frmTest);
14 | Application.Run;
15 | end.
16 |
17 |
--------------------------------------------------------------------------------
/test/backup/pascalobject_seralize_test.lps:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/test/backup/test_pascalobjectseralize.pas:
--------------------------------------------------------------------------------
1 | unit test_pascalobjectseralize;
2 |
3 | {$mode objfpc}{$H+}
4 |
5 | interface
6 |
7 | uses
8 | Classes, SysUtils, typinfo, pascalobject_seralize, intf_seralizeadapter,
9 | fpc_seralizeadapter, dateutils, base64, dbugintf, dbugmsg, frm_Test, fpcunit,
10 | testutils, testregistry;
11 |
12 | type
13 |
14 | { TDataItem }
15 |
16 | TDataItem =Class(TcollectionItem)
17 | private
18 | FDateTime: TDateTime;
19 | fdbl: double;
20 | FInteger: integer;
21 | FStr: string;
22 | published
23 | property testInteger:integer read FInteger write FInteger;
24 | property testDate:TDateTime read FDateTime write FDateTime;
25 | property testString:string read FStr write FStr;
26 | property testFloat:double read fdbl write fdbl;
27 | end;
28 |
29 | { TDataCollection }
30 |
31 | TDataCollection=class(TCollection)
32 |
33 | private
34 | FName: string;
35 | function GetDataItem(Index: integer): TDataItem;
36 | public
37 | function AddDataItem:TDataItem;
38 | property DataItem[Index:integer]:TDataItem read GetDataItem;
39 | published
40 | property datacollectionName:string read FName write FName;
41 | end;
42 | { TestPascalSeralize }
43 |
44 | TestPascalSeralize=class(TTestCase)
45 | protected
46 | Ffrm:TfrmTest;
47 | procedure Setup;override;
48 | procedure TearDown;override;
49 | published
50 | procedure TestGetPropInfo;
51 | end;
52 |
53 | { TestSearalizeObject }
54 |
55 | TestSearalizeObject= class(TTestCase)
56 | protected
57 | FW:TMyCustomWriter;
58 | FR:TMyCustomReader;
59 |
60 | procedure SetUp; override;
61 | procedure TearDown; override;
62 | published
63 | procedure TestReadfrmTest;
64 | procedure TestWritefrmTest;
65 | procedure TestWriteCollection;
66 | procedure TEstReadCollection;
67 |
68 | procedure TestWriteFrmTest_JsonAdapter;
69 | procedure TestReadFrmTest_JsonAdapter;
70 | procedure TestWriteCollection_Json;
71 | procedure TestReadCollection_Json;
72 | procedure TestWriterCollection_XML;
73 | procedure TestReadCollection_XML;
74 | end;
75 | function SampleDataPath:string;
76 | implementation
77 |
78 | function SampleDataPath: string;
79 | begin
80 | result :=GetCurrentDir+'\testData\';
81 | end;
82 |
83 | { TDataCollection }
84 |
85 | function TDataCollection.GetDataItem(Index: integer): TDataItem;
86 | begin
87 | result :=self.Items[Index] as TDataItem;
88 | end;
89 |
90 | function TDataCollection.AddDataItem: TDataItem;
91 | begin
92 | result :=TDataItem.Create(self);
93 | end;
94 |
95 |
96 |
97 | { TestPascalSeralize }
98 |
99 | procedure TestPascalSeralize.Setup;
100 | begin
101 | inherited ;
102 | fFrm :=TfrmTest.Create(nil);
103 | end;
104 |
105 | procedure TestPascalSeralize.TearDown;
106 | begin
107 | FreeAndNil(fFrm);
108 | inherited ;
109 | end;
110 |
111 | procedure TestPascalSeralize.TestGetPropInfo;
112 | var
113 | I: Integer;
114 | PList: PPropList;
115 | intPropCount: Integer;
116 | PInfo: PPropInfo;
117 | begin
118 |
119 |
120 | // Save Collection
121 | intPropCount := GetTypeData(ffrm.ClassInfo)^.PropCount;
122 | GetMem(PList, intPropCount * SizeOf(Pointer));
123 | try
124 | intPropCount := GetPropList(ffrm.ClassInfo, tkAny, PList);
125 | for I := 0 to intPropCount-1 do
126 | begin
127 | PInfo :=PList^[I];
128 |
129 | {$IFOPT D+}
130 | //Please run C:\lazarus\tools\debugserver\debugserver.exe
131 |
132 | SendInteger('Prop Index:',Pinfo^.PropProcs);
133 | SendDebug('PropName:'+Pinfo^.Name);
134 | {$ENDIF}
135 | end;
136 | SendSeparator;
137 | finally
138 | FreeMem(PList, intPropCount * SizeOf(Pointer));
139 | end;
140 |
141 |
142 | end;
143 |
144 | procedure TestSearalizeObject.TestWritefrmTest;
145 | var
146 | Iadp:IDataAdapter;
147 | frm:TfrmTest;
148 | begin
149 | iadp :=TFPCXmlAdapter.Create;
150 | frm :=TfrmTest.Create(nil);
151 | try
152 | fW.Adapter :=Iadp;
153 | frm.Image1.Picture.LoadFromFile(SampleDataPath+'test.png');
154 | frm.ShowModal;
155 | fw.WriteObjectToFile(SampleDataPath+'test.xml',frm);
156 | finally
157 | FreeAndnil(frm);
158 | end;
159 |
160 | end;
161 |
162 | procedure TestSearalizeObject.TestWriteCollection;
163 | var
164 | coll:TDataCollection;
165 | Item:TDataItem;
166 | IAdp:TFPCXmlAdapter;
167 | begin
168 | Coll :=TDatacollection.Create(TdataItem);
169 | IAdp :=TFPCXmlAdapter.Create;
170 | try
171 | Coll.datacollectionName:='TestDataName';
172 |
173 | Item :=coll.AddDataItem;
174 | item.testDate:=now;
175 | item.testFloat:=3.14;
176 | item.testInteger:=28;
177 | item.testString:='hello world';
178 | fw.Adapter :=IAdp;
179 | fw.WriteObjectToFile(SampleDataPath+'testCollection.xml',Coll);
180 |
181 | finally
182 | FreeAndNil( Coll);
183 | end;
184 | end;
185 |
186 | procedure TestSearalizeObject.TEstReadCollection;
187 | var
188 | coll:TDataCollection;
189 | Item:TDataItem;
190 | IAdp:TFPCXmlAdapter;
191 | begin
192 | Coll :=TDatacollection.Create(TdataItem);
193 | IAdp :=TFPCXmlAdapter.Create;
194 | try
195 | fr.Adapter :=IAdp;
196 | fr.ReadFileToObject(SampleDataPath+'testcollection.xml',coll);
197 | checkequals(Coll.datacollectionName,'TestDataName');
198 | Item :=Coll.DataItem[0];
199 |
200 | checkequals(item.testString,'hello world');
201 | checkequals(item.testInteger,28);
202 | checkequals(item.testFloat,3.14);
203 | checkequals(YearOf(item.testDate),yearOf(now));
204 |
205 | finally
206 | FreeAndNil( Coll);
207 | end;
208 |
209 | end;
210 |
211 | procedure TestSearalizeObject.TestWriteFrmTest_JsonAdapter;
212 | var
213 | Iadp:IDataAdapter;
214 | frm:TfrmTest;
215 | begin
216 | iadp :=TFPCJsonAdapter.Create;
217 | frm :=TfrmTest.Create(nil);
218 | try
219 | fW.Adapter :=Iadp;
220 | frm.Image1.Picture.LoadFromFile(SampleDataPath+'test.png');
221 | frm.ShowModal;
222 | fw.WriteObjectToFile(SampleDataPath+'test.json',frm);
223 | finally
224 | FreeAndnil(frm);
225 | end;
226 | end;
227 |
228 | procedure TestSearalizeObject.TestReadFrmTest_JsonAdapter;
229 | var
230 | Iadp:IDataAdapter;
231 | frm:TfrmTest;
232 | begin
233 | iadp :=TFPCJsonAdapter.Create;
234 | frm :=TfrmTest.Create(nil);
235 | try
236 | fr.Adapter :=Iadp;
237 | fr.ReadFileToObject(SampleDataPath+'test.json',frm) ;
238 | frm.ShowModal;
239 | finally
240 | FreeAndnil(frm);
241 | end;
242 |
243 |
244 | end;
245 |
246 | procedure TestSearalizeObject.TestWriteCollection_Json;
247 | var
248 | coll:TDataCollection;
249 | Item:TDataItem;
250 | IAdp:IDataAdapter;
251 | begin
252 | Coll :=TDatacollection.Create(TdataItem);
253 | IAdp :=TFPCJsonAdapter.Create;
254 | try
255 | Coll.datacollectionName:='TestDataName';
256 |
257 | Item :=coll.AddDataItem;
258 | item.testDate:=now;
259 | item.testFloat:=3.14;
260 | item.testInteger:=28;
261 | item.testString:='hello world';
262 | fw.Adapter :=IAdp;
263 | fw.WriteObjectToFile(SampleDataPath+'testCollection.Json',Coll);
264 |
265 | finally
266 | FreeAndNil( Coll);
267 | end;
268 |
269 | end;
270 |
271 | procedure TestSearalizeObject.TestReadCollection_Json;
272 | var
273 | coll:TDataCollection;
274 | Item:TDataItem;
275 | IAdp:IDataAdapter;
276 | begin
277 | Coll :=TDatacollection.Create(TdataItem);
278 | IAdp :=TFPCJsonAdapter.Create;
279 | try
280 | fr.Adapter :=IAdp;
281 | fr.ReadFileToObject(SampleDataPath+'testcollection.Json',coll);
282 | checkequals(Coll.datacollectionName,'TestDataName');
283 | Item :=Coll.DataItem[0];
284 |
285 | checkequals(item.testString,'hello world');
286 | checkequals(item.testInteger,28);
287 | checkequals(item.testFloat,3.14);
288 | checkequals(YearOf(item.testDate),yearOf(now));
289 |
290 | finally
291 | FreeAndNil( Coll);
292 | end;
293 |
294 | end;
295 |
296 | procedure TestSearalizeObject.TestWriterCollection_XML;
297 | var
298 | coll:TDataCollection;
299 | Item:TDataItem;
300 | IAdp:IDataAdapter;
301 | begin
302 | Coll :=TDatacollection.Create(TdataItem);
303 | IAdp :=TFPCXmlAdapter.Create;
304 | try
305 | Coll.datacollectionName:='TestDataName';
306 |
307 | Item :=coll.AddDataItem;
308 | item.testDate:=now;
309 | item.testFloat:=3.14;
310 | item.testInteger:=28;
311 | item.testString:='hello world';
312 | fw.Adapter :=IAdp;
313 | fw.WriteObjectToFile(SampleDataPath+'testCollection.XML',Coll);
314 |
315 | finally
316 | FreeAndNil( Coll);
317 | end;
318 | end;
319 |
320 | procedure TestSearalizeObject.TestReadCollection_XML;
321 | var
322 | coll:TDataCollection;
323 | Item:TDataItem;
324 | IAdp:IDataAdapter;
325 | begin
326 | Coll :=TDatacollection.Create(TdataItem);
327 | IAdp :=TFPCXmlAdapter.Create;
328 | try
329 | fr.Adapter :=IAdp;
330 | fr.ReadFileToObject(SampleDataPath+'testcollection.Json',coll);
331 | checkequals(Coll.datacollectionName,'TestDataName');
332 | Item :=Coll.DataItem[0];
333 |
334 | checkequals(item.testString,'hello world');
335 | checkequals(item.testInteger,28);
336 | checkequals(item.testFloat,3.14);
337 | checkequals(YearOf(item.testDate),yearOf(now));
338 |
339 | finally
340 | FreeAndNil( Coll);
341 | end;
342 | end;
343 |
344 | procedure TestSearalizeObject.SetUp;
345 | begin
346 | FW :=TMyCustomWriter.Create(nil);
347 | Fr :=TMyCustomReader.Create(nil);
348 | end;
349 |
350 | procedure TestSearalizeObject.TearDown;
351 | begin
352 | FreeAndnil(Fr);
353 | FreeAndNil(FW);
354 | end;
355 |
356 |
357 |
358 | procedure TestSearalizeObject.TestReadfrmTest;
359 | var
360 | Iadp:IDataAdapter;
361 | frm:TfrmTest;
362 | begin
363 | iadp :=TFPCXmlAdapter.Create;
364 | frm :=TfrmTest.Create(nil);
365 | try
366 | fr.Adapter :=Iadp;
367 | fr.ReadFileToObject(SampleDataPath+'test.xml',frm) ;
368 | frm.ShowModal;
369 | finally
370 | FreeAndnil(frm);
371 | end;
372 |
373 |
374 | end;
375 |
376 |
377 |
378 |
379 |
380 | initialization
381 | RegisterClass(TDatacollection);
382 | RegisterClass(TDataItem);
383 | RegisterTest(TestPascalSeralize);
384 | RegisterTest(TestSearalizeObject);
385 | end.
386 |
387 |
--------------------------------------------------------------------------------
/test/backup/testfpc_seralizeadapter_test.pas:
--------------------------------------------------------------------------------
1 | unit testfpc_seralizeadapter_test;
2 |
3 | {$mode objfpc}{$H+}
4 |
5 | interface
6 |
7 | uses
8 | Classes, SysUtils, fpc_seralizeadapter, Forms, intf_seralizeadapter, dbugintf,
9 | fpjson, jsonparser, Laz_XMLRead, Laz2_DOM, laz2_XMLWrite, Laz_XMLWrite,
10 | fpcunit, testutils, testregistry;
11 |
12 | type
13 |
14 | { TXMLAccessTest }
15 |
16 | TXMLAccessTest=class(TTestCase)
17 | private
18 | fDoc:TXMLDocument;
19 | protected
20 | procedure SetUp; override;
21 | procedure TearDown; override;
22 | published
23 | procedure TestReadXML;
24 | Procedure TestAccessXMLAttribute;
25 | procedure TestAddAttribute;
26 | end;
27 |
28 | { TJSonAccessTest }
29 |
30 | TJSonAccessTest=class(TTestCase)
31 | private
32 |
33 | protected
34 | procedure SetUp;override;
35 | procedure TearDown; override;
36 | published
37 | procedure TestJsonAccess;
38 | end;
39 |
40 | TFpcAdapterTest= class(TTestCase)
41 | private
42 | FXML:TFPCXmlAdapter;
43 |
44 | protected
45 | procedure SetUp; override;
46 | procedure TearDown; override;
47 | published
48 | procedure XMLTest;
49 | end;
50 |
51 | implementation
52 |
53 | { TJSonAccessTest }
54 |
55 | procedure TJSonAccessTest.SetUp;
56 | begin
57 | inherited ;
58 | end;
59 |
60 | procedure TJSonAccessTest.TearDown;
61 | begin
62 | inherited ;
63 | end;
64 |
65 | procedure TJSonAccessTest.TestJsonAccess;
66 | var
67 | JData,JItem:TJSONData;
68 | JObj:TJsonObject;
69 | begin
70 | JData :=getJson('{"JSONDATA":{}}');
71 | Jobj :=JData as TJsonObject;
72 | try
73 | SendInteger(Jobj.Count);
74 | Jobj :=(JData as TJsonObject).Items[0] as TJsonObject;
75 | Jobj.Add('testnod1',35);
76 | jobj.Add('testnod2',true);
77 | senddebug(jobj.AsJSON);
78 |
79 |
80 | checkequals(JObj.Items[0].AsString,'35');
81 | checkequals(jobj.Items[1].AsString,'True');
82 | senddebug(jobj.Items[1].AsString);
83 |
84 | finally
85 | FreeAndNil(JData);
86 | end;
87 |
88 | end;
89 |
90 | { TXMLAccessTest }
91 |
92 | procedure TXMLAccessTest.SetUp;
93 | var
94 | Path:string;
95 | begin
96 | Path :=GetCurrentDir();
97 | ReadXMLFile(fDoc,Path+'\testdata\test.xml');
98 | end;
99 |
100 | procedure TXMLAccessTest.TearDown;
101 | begin
102 | if Assigned(fDoc) then
103 | begin
104 | FreeAndnil(fDoc);
105 | end;
106 | end;
107 |
108 | procedure TXMLAccessTest.TestReadXML;
109 | var
110 | FirstNode:TDOMNode;
111 | begin
112 | FirstNode :=fDoc.ChildNodes[0];
113 |
114 | checkequals(FirstNode.NodeName,'XMLOBJECT');
115 |
116 | end;
117 |
118 | procedure TXMLAccessTest.TestAccessXMLAttribute;
119 | var
120 | FirstNode:TDOMNode;
121 | begin
122 | FirstNode :=fDoc.ChildNodes[0];
123 | Checkequals(Firstnode.Attributes.Item[0].NodeValue,'TComponent');
124 |
125 | checkequals(FirstNode.Attributes.GetNamedItem('PersistentType').NodeValue,'TComponent');
126 | Checkequals(Firstnode.Attributes.GetNamedItem('ClassType').NodeValue,'TCodeLib');
127 | end;
128 |
129 | procedure TXMLAccessTest.TestAddAttribute;
130 | var
131 | FirstNode:TDOMNode;
132 | attrNode:TDOMAttr;
133 | attrs:TDOMNamedNodeMap;
134 | begin
135 | FirstNode :=fDoc.ChildNodes[0];
136 | attrNode :=fDoc.CreateAttribute('wac');
137 | (FirstNode as TDomElement).SetAttribute('wac','test');
138 |
139 | WriteXML(fDoc,'e:\test.xml');
140 | end;
141 |
142 | procedure TFpcAdapterTest.XMLTest;
143 |
144 | begin
145 |
146 | end;
147 |
148 | procedure TFpcAdapterTest.SetUp;
149 | begin
150 | Fxml :=TFPCXmlAdapter.Create;
151 | end;
152 |
153 | procedure TFpcAdapterTest.TearDown;
154 | begin
155 | FreeandNil(FXML);
156 | end;
157 |
158 | initialization
159 | RegisterTest(TJSonAccessTest);
160 | RegisterTest(TXMLAccessTest);
161 | RegisterTest(TFpcAdapterTest);
162 | end.
163 |
164 |
--------------------------------------------------------------------------------
/test/frm_test.lfm:
--------------------------------------------------------------------------------
1 | object frmTest: TfrmTest
2 | Left = 754
3 | Height = 373
4 | Top = 155
5 | Width = 427
6 | AllowDropFiles = True
7 | Caption = 'Action1'
8 | ClientHeight = 373
9 | ClientWidth = 427
10 | OnCreate = FormCreate
11 | LCLVersion = '1.6.4.0'
12 | object Image1: TImage
13 | Left = 16
14 | Height = 178
15 | Top = 24
16 | Width = 322
17 | end
18 | object Button1: TButton
19 | Left = 16
20 | Height = 25
21 | Top = 232
22 | Width = 75
23 | Action = actTest
24 | TabOrder = 0
25 | end
26 | object ActionList1: TActionList
27 | left = 335
28 | top = 233
29 | object actTest: TAction
30 | Caption = 'Action1'
31 | OnExecute = actTestExecute
32 | end
33 | end
34 | end
35 |
--------------------------------------------------------------------------------
/test/frm_test.pas:
--------------------------------------------------------------------------------
1 | unit frm_Test;
2 |
3 | {$mode objfpc}{$H+}
4 |
5 | interface
6 |
7 | uses
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
9 | StdCtrls, ActnList;
10 |
11 | type
12 |
13 | { TfrmTest }
14 |
15 | TfrmTest = class(TForm)
16 | published
17 | actTest: TAction;
18 | ActionList1: TActionList;
19 | Button1: TButton;
20 | Image1: TImage;
21 | procedure actTestExecute(Sender: TObject);
22 | procedure FormCreate(Sender: TObject);
23 | private
24 | { private declarations }
25 | public
26 | { public declarations }
27 | end;
28 |
29 | var
30 | frmTest: TfrmTest;
31 |
32 | implementation
33 |
34 | {$R *.lfm}
35 |
36 | { TfrmTest }
37 |
38 | procedure TfrmTest.FormCreate(Sender: TObject);
39 | begin
40 |
41 | end;
42 |
43 | procedure TfrmTest.actTestExecute(Sender: TObject);
44 | begin
45 |
46 | end;
47 |
48 | end.
49 |
50 |
--------------------------------------------------------------------------------
/test/pascalobject_seralize_test.compiled:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/test/pascalobject_seralize_test.fpcunit.ini:
--------------------------------------------------------------------------------
1 | [WindowState]
2 | Left=238
3 | Top=96
4 | Width=575
5 | Height=663
6 |
7 | [Tests]
8 | All Tests.Checked=0
9 | All Tests.Expanded=1
10 | TJSonAccessTest.Checked=0
11 | TJSonAccessTest.Expanded=1
12 | TJSonAccessTest.TestJsonAccess.Checked=0
13 | TJSonAccessTest.TestJsonAccess.Expanded=0
14 | TXMLAccessTest.Checked=0
15 | TXMLAccessTest.Expanded=1
16 | TXMLAccessTest.TestReadXML.Checked=0
17 | TXMLAccessTest.TestReadXML.Expanded=0
18 | TXMLAccessTest.TestAccessXMLAttribute.Checked=0
19 | TXMLAccessTest.TestAccessXMLAttribute.Expanded=0
20 | TXMLAccessTest.TestAddAttribute.Checked=0
21 | TXMLAccessTest.TestAddAttribute.Expanded=0
22 | TFpcAdapterTest.Checked=1
23 | TFpcAdapterTest.Expanded=1
24 | TFpcAdapterTest.XMLTest.Checked=1
25 | TFpcAdapterTest.XMLTest.Expanded=0
26 | TestPascalSeralize.Checked=1
27 | TestPascalSeralize.Expanded=1
28 | TestPascalSeralize.TestGetPropInfo.Checked=1
29 | TestPascalSeralize.TestGetPropInfo.Expanded=0
30 | TestSearalizeObject.Checked=1
31 | TestSearalizeObject.Expanded=1
32 | TestSearalizeObject.TestReadfrmTest.Checked=1
33 | TestSearalizeObject.TestReadfrmTest.Expanded=0
34 | TestSearalizeObject.TestWritefrmTest.Checked=1
35 | TestSearalizeObject.TestWritefrmTest.Expanded=0
36 | TestSearalizeObject.TestWriteCollection.Checked=1
37 | TestSearalizeObject.TestWriteCollection.Expanded=0
38 | TestSearalizeObject.TEstReadCollection.Checked=1
39 | TestSearalizeObject.TEstReadCollection.Expanded=0
40 | TestSearalizeObject.TestWriteFrmTest_JsonAdapter.Checked=1
41 | TestSearalizeObject.TestWriteFrmTest_JsonAdapter.Expanded=0
42 | TestSearalizeObject.TestReadFrmTest_JsonAdapter.Checked=1
43 | TestSearalizeObject.TestReadFrmTest_JsonAdapter.Expanded=0
44 | TestSearalizeObject.TestWriteCollection_Json.Checked=1
45 | TestSearalizeObject.TestWriteCollection_Json.Expanded=0
46 | TestSearalizeObject.TestReadCollection_Json.Checked=1
47 | TestSearalizeObject.TestReadCollection_Json.Expanded=0
48 | TestSearalizeObject.TestWriterCollection_XML.Checked=1
49 | TestSearalizeObject.TestWriterCollection_XML.Expanded=0
50 | TestSearalizeObject.TestReadCollection_XML.Checked=1
51 | TestSearalizeObject.TestReadCollection_XML.Expanded=0
52 |
--------------------------------------------------------------------------------
/test/pascalobject_seralize_test.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ericwang1104/PascalObjectSeralize/911dcbd0a2ce84cdca8a14b0812758d0133e2ef4/test/pascalobject_seralize_test.ico
--------------------------------------------------------------------------------
/test/pascalobject_seralize_test.lpi:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/test/pascalobject_seralize_test.lpr:
--------------------------------------------------------------------------------
1 | program pascalobject_seralize_test;
2 |
3 | {$mode objfpc}{$H+}
4 | uses
5 | Interfaces, Forms,GuiTestRunner, testfpc_seralizeadapter_test,
6 | test_pascalobjectseralize, frm_Test;
7 |
8 | {$R *.res}
9 |
10 | begin
11 | Application.Scaled:=True;
12 | Application.Initialize;
13 | Application.CreateForm(TGuiTestRunner, TestRunner);
14 | Application.CreateForm(TfrmTest, frmTest);
15 | Application.Run;
16 | end.
17 |
18 |
--------------------------------------------------------------------------------
/test/pascalobject_seralize_test.lps:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/test/pascalobject_seralize_test.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ericwang1104/PascalObjectSeralize/911dcbd0a2ce84cdca8a14b0812758d0133e2ef4/test/pascalobject_seralize_test.res
--------------------------------------------------------------------------------
/test/test_pascalobjectseralize.pas:
--------------------------------------------------------------------------------
1 | unit test_pascalobjectseralize;
2 |
3 | {$mode objfpc}{$H+}
4 |
5 | interface
6 |
7 | uses
8 | Classes, SysUtils, typinfo, pascalobject_seralize, intf_seralizeadapter,
9 | fpc_seralizeadapter, dateutils, base64, dbugintf, dbugmsg, frm_Test, fpcunit,
10 | testutils, testregistry;
11 |
12 | type
13 |
14 | { TDataItem }
15 |
16 | TDataItem =Class(TcollectionItem)
17 | private
18 | FDateTime: TDateTime;
19 | fdbl: double;
20 | FInteger: integer;
21 | FStr: string;
22 | published
23 | property testInteger:integer read FInteger write FInteger;
24 | property testDate:TDateTime read FDateTime write FDateTime;
25 | property testString:string read FStr write FStr;
26 | property testFloat:double read fdbl write fdbl;
27 | end;
28 |
29 | { TDataCollection }
30 |
31 | TDataCollection=class(TCollection)
32 |
33 | private
34 | FName: string;
35 | function GetDataItem(Index: integer): TDataItem;
36 | public
37 | function AddDataItem:TDataItem;
38 | property DataItem[Index:integer]:TDataItem read GetDataItem;
39 | published
40 | property datacollectionName:string read FName write FName;
41 | end;
42 | { TestPascalSeralize }
43 |
44 | TestPascalSeralize=class(TTestCase)
45 | protected
46 | Ffrm:TfrmTest;
47 | procedure Setup;override;
48 | procedure TearDown;override;
49 | published
50 | procedure TestGetPropInfo;
51 | end;
52 |
53 | { TestSearalizeObject }
54 |
55 | TestSearalizeObject= class(TTestCase)
56 | protected
57 | FW:TMyCustomWriter;
58 | FR:TMyCustomReader;
59 |
60 | procedure SetUp; override;
61 | procedure TearDown; override;
62 | published
63 | procedure TestReadfrmTest;
64 | procedure TestWritefrmTest;
65 | procedure TestWriteCollection;
66 | procedure TEstReadCollection;
67 |
68 | procedure TestWriteFrmTest_JsonAdapter;
69 | procedure TestReadFrmTest_JsonAdapter;
70 | procedure TestWriteCollection_Json;
71 | procedure TestReadCollection_Json;
72 | procedure TestWriterCollection_XML;
73 | procedure TestReadCollection_XML;
74 | end;
75 | function SampleDataPath:string;
76 | implementation
77 |
78 | function SampleDataPath: string;
79 | begin
80 | result :=GetCurrentDir+'\testData\';
81 | end;
82 |
83 | { TDataCollection }
84 |
85 | function TDataCollection.GetDataItem(Index: integer): TDataItem;
86 | begin
87 | result :=self.Items[Index] as TDataItem;
88 | end;
89 |
90 | function TDataCollection.AddDataItem: TDataItem;
91 | begin
92 | result :=TDataItem.Create(self);
93 | end;
94 |
95 |
96 |
97 | { TestPascalSeralize }
98 |
99 | procedure TestPascalSeralize.Setup;
100 | begin
101 | inherited ;
102 | fFrm :=TfrmTest.Create(nil);
103 | end;
104 |
105 | procedure TestPascalSeralize.TearDown;
106 | begin
107 | FreeAndNil(fFrm);
108 | inherited ;
109 | end;
110 |
111 | procedure TestPascalSeralize.TestGetPropInfo;
112 | var
113 | I: Integer;
114 | PList: PPropList;
115 | intPropCount: Integer;
116 | PInfo: PPropInfo;
117 | begin
118 |
119 |
120 | // Save Collection
121 | intPropCount := GetTypeData(ffrm.ClassInfo)^.PropCount;
122 | GetMem(PList, intPropCount * SizeOf(Pointer));
123 | try
124 | intPropCount := GetPropList(ffrm.ClassInfo, tkAny, PList);
125 | for I := 0 to intPropCount-1 do
126 | begin
127 | PInfo :=PList^[I];
128 |
129 | {$IFOPT D+}
130 | //Please run C:\lazarus\tools\debugserver\debugserver.exe
131 |
132 | SendInteger('Prop Index:',Pinfo^.PropProcs);
133 | SendDebug('PropName:'+Pinfo^.Name);
134 | {$ENDIF}
135 | end;
136 | SendSeparator;
137 | finally
138 | FreeMem(PList, intPropCount * SizeOf(Pointer));
139 | end;
140 |
141 |
142 | end;
143 |
144 | procedure TestSearalizeObject.TestWritefrmTest;
145 | var
146 | Iadp:IDataAdapter;
147 | frm:TfrmTest;
148 | begin
149 | iadp :=TFPCXmlAdapter.Create;
150 | frm :=TfrmTest.Create(nil);
151 | try
152 | fW.Adapter :=Iadp;
153 | frm.Image1.Picture.LoadFromFile(SampleDataPath+'test.png');
154 | frm.ShowModal;
155 | fw.WriteObjectToFile(SampleDataPath+'test.xml',frm);
156 | finally
157 | FreeAndnil(frm);
158 | end;
159 |
160 | end;
161 |
162 | procedure TestSearalizeObject.TestWriteCollection;
163 | var
164 | coll:TDataCollection;
165 | Item:TDataItem;
166 | IAdp:TFPCXmlAdapter;
167 | begin
168 | Coll :=TDatacollection.Create(TdataItem);
169 | IAdp :=TFPCXmlAdapter.Create;
170 | try
171 | Coll.datacollectionName:='TestDataName';
172 |
173 | Item :=coll.AddDataItem;
174 | item.testDate:=now;
175 | item.testFloat:=3.14;
176 | item.testInteger:=28;
177 | item.testString:='hello world';
178 | fw.Adapter :=IAdp;
179 | fw.WriteObjectToFile(SampleDataPath+'testCollection.xml',Coll);
180 |
181 | finally
182 | FreeAndNil( Coll);
183 | end;
184 | end;
185 |
186 | procedure TestSearalizeObject.TEstReadCollection;
187 | var
188 | coll:TDataCollection;
189 | Item:TDataItem;
190 | IAdp:TFPCXmlAdapter;
191 | begin
192 | Coll :=TDatacollection.Create(TdataItem);
193 | IAdp :=TFPCXmlAdapter.Create;
194 | try
195 | fr.Adapter :=IAdp;
196 | fr.ReadFileToObject(SampleDataPath+'testcollection.xml',coll);
197 | checkequals(Coll.datacollectionName,'TestDataName');
198 | Item :=Coll.DataItem[0];
199 |
200 | checkequals(item.testString,'hello world');
201 | checkequals(item.testInteger,28);
202 | checkequals(item.testFloat,3.14);
203 | checkequals(YearOf(item.testDate),yearOf(now));
204 |
205 | finally
206 | FreeAndNil( Coll);
207 | end;
208 |
209 | end;
210 |
211 | procedure TestSearalizeObject.TestWriteFrmTest_JsonAdapter;
212 | var
213 | Iadp:IDataAdapter;
214 | frm:TfrmTest;
215 | begin
216 | iadp :=TFPCJsonAdapter.Create;
217 | frm :=TfrmTest.Create(nil);
218 | try
219 | fW.Adapter :=Iadp;
220 | frm.Image1.Picture.LoadFromFile(SampleDataPath+'test.png');
221 | frm.ShowModal;
222 | fw.WriteObjectToFile(SampleDataPath+'test.json',frm);
223 | finally
224 | FreeAndnil(frm);
225 | end;
226 | end;
227 |
228 | procedure TestSearalizeObject.TestReadFrmTest_JsonAdapter;
229 | var
230 | Iadp:IDataAdapter;
231 | frm:TfrmTest;
232 | begin
233 | iadp :=TFPCJsonAdapter.Create;
234 | frm :=TfrmTest.Create(nil);
235 | try
236 | fr.Adapter :=Iadp;
237 | fr.ReadFileToObject(SampleDataPath+'test.json',frm) ;
238 | frm.ShowModal;
239 | finally
240 | FreeAndnil(frm);
241 | end;
242 |
243 |
244 | end;
245 |
246 | procedure TestSearalizeObject.TestWriteCollection_Json;
247 | var
248 | coll:TDataCollection;
249 | Item:TDataItem;
250 | IAdp:IDataAdapter;
251 | begin
252 | Coll :=TDatacollection.Create(TdataItem);
253 | IAdp :=TFPCJsonAdapter.Create;
254 | try
255 | Coll.datacollectionName:='TestDataName';
256 |
257 | Item :=coll.AddDataItem;
258 | item.testDate:=now;
259 | item.testFloat:=3.14;
260 | item.testInteger:=28;
261 | item.testString:='hello world';
262 | fw.Adapter :=IAdp;
263 | fw.WriteObjectToFile(SampleDataPath+'testCollection.Json',Coll);
264 |
265 | finally
266 | FreeAndNil( Coll);
267 | end;
268 |
269 | end;
270 |
271 | procedure TestSearalizeObject.TestReadCollection_Json;
272 | var
273 | coll:TDataCollection;
274 | Item:TDataItem;
275 | IAdp:IDataAdapter;
276 | begin
277 | Coll :=TDatacollection.Create(TdataItem);
278 | IAdp :=TFPCJsonAdapter.Create;
279 | try
280 | fr.Adapter :=IAdp;
281 | fr.ReadFileToObject(SampleDataPath+'testcollection.Json',coll);
282 | checkequals(Coll.datacollectionName,'TestDataName');
283 | Item :=Coll.DataItem[0];
284 |
285 | checkequals(item.testString,'hello world');
286 | checkequals(item.testInteger,28);
287 | checkequals(item.testFloat,3.14);
288 | checkequals(YearOf(item.testDate),yearOf(now));
289 |
290 | finally
291 | FreeAndNil( Coll);
292 | end;
293 |
294 | end;
295 |
296 | procedure TestSearalizeObject.TestWriterCollection_XML;
297 | var
298 | coll:TDataCollection;
299 | Item:TDataItem;
300 | IAdp:IDataAdapter;
301 | begin
302 | Coll :=TDatacollection.Create(TdataItem);
303 | IAdp :=TFPCXmlAdapter.Create;
304 | try
305 | Coll.datacollectionName:='TestDataName';
306 |
307 | Item :=coll.AddDataItem;
308 | item.testDate:=now;
309 | item.testFloat:=3.14;
310 | item.testInteger:=28;
311 | item.testString:='hello world';
312 | fw.Adapter :=IAdp;
313 | fw.WriteObjectToFile(SampleDataPath+'testCollection.XML',Coll);
314 |
315 | finally
316 | FreeAndNil( Coll);
317 | end;
318 | end;
319 |
320 | procedure TestSearalizeObject.TestReadCollection_XML;
321 | var
322 | coll:TDataCollection;
323 | Item:TDataItem;
324 | IAdp:IDataAdapter;
325 | begin
326 | Coll :=TDatacollection.Create(TdataItem);
327 | IAdp :=TFPCXmlAdapter.Create;
328 | try
329 | fr.Adapter :=IAdp;
330 | fr.ReadFileToObject(SampleDataPath+'testcollection.XML',coll);
331 | checkequals(Coll.datacollectionName,'TestDataName');
332 | Item :=Coll.DataItem[0];
333 |
334 | checkequals(item.testString,'hello world');
335 | checkequals(item.testInteger,28);
336 | checkequals(item.testFloat,3.14);
337 | checkequals(YearOf(item.testDate),yearOf(now));
338 |
339 | finally
340 | FreeAndNil( Coll);
341 | end;
342 | end;
343 |
344 | procedure TestSearalizeObject.SetUp;
345 | begin
346 | FW :=TMyCustomWriter.Create(nil);
347 | Fr :=TMyCustomReader.Create(nil);
348 | end;
349 |
350 | procedure TestSearalizeObject.TearDown;
351 | begin
352 | FreeAndnil(Fr);
353 | FreeAndNil(FW);
354 | end;
355 |
356 |
357 |
358 | procedure TestSearalizeObject.TestReadfrmTest;
359 | var
360 | Iadp:IDataAdapter;
361 | frm:TfrmTest;
362 | begin
363 | iadp :=TFPCXmlAdapter.Create;
364 | frm :=TfrmTest.Create(nil);
365 | try
366 | fr.Adapter :=Iadp;
367 | fr.ReadFileToObject(SampleDataPath+'test.xml',frm) ;
368 | frm.ShowModal;
369 | finally
370 | FreeAndnil(frm);
371 | end;
372 |
373 |
374 | end;
375 |
376 |
377 |
378 |
379 |
380 | initialization
381 | RegisterClass(TDatacollection);
382 | RegisterClass(TDataItem);
383 | RegisterTest(TestPascalSeralize);
384 | RegisterTest(TestSearalizeObject);
385 | end.
386 |
387 |
--------------------------------------------------------------------------------
/test/testcase1.pas:
--------------------------------------------------------------------------------
1 | unit TestCase1;
2 |
3 | {$mode objfpc}{$H+}
4 |
5 | interface
6 |
7 | uses
8 | Classes, SysUtils, fpcunit, testutils, testregistry;
9 |
10 | type
11 |
12 | TTestCase1= class(TTestCase)
13 | published
14 | procedure TestHookUp;
15 | end;
16 |
17 | implementation
18 |
19 | procedure TTestCase1.TestHookUp;
20 | begin
21 | Fail('Write your own test');
22 | end;
23 |
24 |
25 |
26 | initialization
27 |
28 | RegisterTest(TTestCase1);
29 | end.
30 |
31 |
--------------------------------------------------------------------------------
/test/testdata/test.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ericwang1104/PascalObjectSeralize/911dcbd0a2ce84cdca8a14b0812758d0133e2ef4/test/testdata/test.png
--------------------------------------------------------------------------------
/test/testdata/test.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/test/testdata/testCollection.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/test/testfpc_seralizeadapter_test.pas:
--------------------------------------------------------------------------------
1 | unit testfpc_seralizeadapter_test;
2 |
3 | {$mode objfpc}{$H+}
4 |
5 | interface
6 |
7 | uses
8 | Classes, SysUtils, fpc_seralizeadapter, Forms, intf_seralizeadapter, dbugintf,
9 | fpjson, jsonparser, Laz_XMLRead, Laz2_DOM, laz2_XMLWrite, Laz_XMLWrite,
10 | fpcunit, testutils, testregistry;
11 |
12 | type
13 |
14 | { TXMLAccessTest }
15 |
16 | TXMLAccessTest=class(TTestCase)
17 | private
18 | fDoc:TXMLDocument;
19 | protected
20 | procedure SetUp; override;
21 | procedure TearDown; override;
22 | published
23 | procedure TestReadXML;
24 | Procedure TestAccessXMLAttribute;
25 | procedure TestAddAttribute;
26 | end;
27 |
28 | { TJSonAccessTest }
29 |
30 | TJSonAccessTest=class(TTestCase)
31 | private
32 |
33 | protected
34 | procedure SetUp;override;
35 | procedure TearDown; override;
36 | published
37 | procedure TestJsonAccess;
38 | end;
39 |
40 | TFpcAdapterTest= class(TTestCase)
41 | private
42 | FXML:TFPCXmlAdapter;
43 |
44 | protected
45 | procedure SetUp; override;
46 | procedure TearDown; override;
47 | published
48 | procedure XMLTest;
49 | end;
50 |
51 | implementation
52 |
53 | { TJSonAccessTest }
54 |
55 | procedure TJSonAccessTest.SetUp;
56 | begin
57 | inherited ;
58 | end;
59 |
60 | procedure TJSonAccessTest.TearDown;
61 | begin
62 | inherited ;
63 | end;
64 |
65 | procedure TJSonAccessTest.TestJsonAccess;
66 | var
67 | JData,JItem:TJSONData;
68 | JObj:TJsonObject;
69 | begin
70 | JData :=getJson('{"JSONDATA":{}}');
71 | Jobj :=JData as TJsonObject;
72 | try
73 | SendInteger('JSONDATA',Jobj.Count);
74 | Jobj :=(JData as TJsonObject).Items[0] as TJsonObject;
75 | Jobj.Add('testnod1',35);
76 | jobj.Add('testnod2',true);
77 | senddebug(jobj.AsJSON);
78 |
79 |
80 | checkequals(JObj.Items[0].AsString,'35');
81 | checkequals(jobj.Items[1].AsString,'True');
82 | senddebug(jobj.Items[1].AsString);
83 |
84 | finally
85 | FreeAndNil(JData);
86 | end;
87 |
88 | end;
89 |
90 | { TXMLAccessTest }
91 |
92 | procedure TXMLAccessTest.SetUp;
93 | var
94 | Path:string;
95 | begin
96 | Path :=GetCurrentDir();
97 | ReadXMLFile(fDoc,Path+'\testdata\test.xml');
98 | end;
99 |
100 | procedure TXMLAccessTest.TearDown;
101 | begin
102 | if Assigned(fDoc) then
103 | begin
104 | FreeAndnil(fDoc);
105 | end;
106 | end;
107 |
108 | procedure TXMLAccessTest.TestReadXML;
109 | var
110 | FirstNode:TDOMNode;
111 | begin
112 | FirstNode :=fDoc.ChildNodes[0];
113 |
114 | checkequals(FirstNode.NodeName,'XMLOBJECT');
115 |
116 | end;
117 |
118 | procedure TXMLAccessTest.TestAccessXMLAttribute;
119 | var
120 | FirstNode:TDOMNode;
121 | begin
122 | FirstNode :=fDoc.ChildNodes[0];
123 | Checkequals(Firstnode.Attributes.Item[0].NodeValue,'TComponent');
124 |
125 | checkequals(FirstNode.Attributes.GetNamedItem('PersistentType').NodeValue,'TComponent');
126 | Checkequals(Firstnode.Attributes.GetNamedItem('ClassType').NodeValue,'TCodeLib');
127 | end;
128 |
129 | procedure TXMLAccessTest.TestAddAttribute;
130 | var
131 | FirstNode:TDOMNode;
132 | attrNode:TDOMAttr;
133 | attrs:TDOMNamedNodeMap;
134 | begin
135 | FirstNode :=fDoc.ChildNodes[0];
136 | attrNode :=fDoc.CreateAttribute('wac');
137 | (FirstNode as TDomElement).SetAttribute('wac','test');
138 |
139 | WriteXML(fDoc,'e:\test.xml');
140 | end;
141 |
142 | procedure TFpcAdapterTest.XMLTest;
143 |
144 | begin
145 |
146 | end;
147 |
148 | procedure TFpcAdapterTest.SetUp;
149 | begin
150 | Fxml :=TFPCXmlAdapter.Create;
151 | end;
152 |
153 | procedure TFpcAdapterTest.TearDown;
154 | begin
155 | FreeandNil(FXML);
156 | end;
157 |
158 | initialization
159 | RegisterTest(TJSonAccessTest);
160 | RegisterTest(TXMLAccessTest);
161 | RegisterTest(TFpcAdapterTest);
162 | end.
163 |
164 |
--------------------------------------------------------------------------------