-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathxmlopenBorSystemClass.pas
More file actions
executable file
·657 lines (645 loc) · 18.1 KB
/
xmlopenBorSystemClass.pas
File metadata and controls
executable file
·657 lines (645 loc) · 18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
//V 1.09
//This Class was generated with Total Text Container
//This example is to be used in conjunction with delphi's xml dataBinder.....
//First create a xsd file somewhere on you're pc.... you'll find that in the code tree section to the left under Xml>>Xsd
//Then in delphi File>>New>>Other>>xml data binder. Load up the xsd file and follow instructions.
//Then save xml data binder class that was generated within delphi and call that class in the uses clause of this class.
//Save this class as xmlopenBorSystemClass
unit xmlopenBorSystemClass;
interface
Uses
xmlopenBorSystem, Classes, graphics, MarioSec, MarioZip;
Type
ropenBorSystem = Record
id : Integer;
gd : String;
title : String;
dscrp : String;
htyp : Integer;
vald : String;
lgth : String;
usd : String;
avar : string;
Multiple : Integer;
iCommand : Integer;
//New
Group : string;
//Scripts
ScrResult : String;
ScrName : String;
ScrCode : String;
ScrType : integer;
//Tree only
hasCommand : boolean;
end;
popenBorSystem = ^ropenBorSystem;
Type
aXmlopenBorSystem = class
Private
fxmlFile : String;
fTree : IXMLTopenBorSystemDef;
fData :ropenBorSystem;
Public
fopenBorSystem : IXMLTopenBorSystemDefList;
Modified : Boolean;
//Manipulation
Function addopenBorSystemData(pData:popenBorSystem):Boolean; Overload;
Function addopenBorSystemData(rData:ropenBorSystem):Boolean; Overload;
Function setopenBorSystemData(pData:popenBorSystem):Boolean; Overload;
Function setopenBorSystemData(rData:ropenBorSystem):Boolean; Overload;
Function setopenBorSystemData(xmlID:Integer;rData:ropenBorSystem):Boolean; Overload;
Function setopenBorSystemDataViagd(rData:ropenBorSystem):Boolean;
Function delopenBorSystemData(pData:popenBorSystem):Boolean; Overload;
Function delopenBorSystemData(rData:ropenBorSystem):Boolean; Overload;
Function delopenBorSystemData(ItemID:Integer):Boolean; Overload;
//Retrieval
Function getopenBorSystemData(xmlID :Integer):ropenBorSystem;
Function getopenBorSystemDataViaID(ItemID:Integer):ropenBorSystem;
Function getopenBorSystemDataViagd(gd:wideString):ropenBorSystem;
Function pData2openBorSystemrData(pData:popenBorSystem):ropenBorSystem;
function getGroupList(glossaryType:integer):TStringList;
Function getHighestopenBorSystemID:Integer;
Function getopenBorSystemXmlID(pData:popenBorSystem):Integer; Overload;
Function getopenBorSystemXmlID(rData:ropenBorSystem):Integer; Overload;
Function getopenBorSystemNew:ropenBorSystem;
function clearopenBorSystemrData(rData:ropenBorSystem):ropenBorSystem;
//Misc
procedure importFromFile(EntitySystemFile:String;asType:Integer);
Function SavetoFile(xmlFile:String):Boolean;
{Function SavetoZip:Boolean;
Function loadFromZip:aXmlopenBorSystem;}
Function verifyXml(aFileName:String):Boolean;
constructor Create(xmlFile:String); Overload;
Destructor Destroy; override;
end;
implementation
uses SysUtils, XMLIntf, unCommon;
{ aXmlopenBorSystem }
function aXmlopenBorSystem.addopenBorSystemData(pData: popenBorSystem): Boolean;
Var
rData : ropenBorSystem;
begin
rData := pData2openBorSystemrData(pData);
addopenBorSystemData(rData);
end;
function aXmlopenBorSystem.addopenBorSystemData(rData: ropenBorSystem): Boolean;
Begin
Try
Result := False;
//if fopenBorSystem = nil then
try
//fopenBorSystem := NewTopenBorSystemList;
except
end;
fTree := fopenBorSystem.Add;
fTree.id := rData.id;
fTree.gd := rData.gd;
fTree.title := rData.title;
fTree.dscrp := EncodeString(rData.dscrp);
fTree.htyp := rData.htyp;
fTree.vald := rData.vald;
fTree.lgth := rData.lgth;
fTree.usd := rData.usd;
fTree.avar := rData.avar;
fTree.Mltp := rData.Multiple;
fTree.Icmd := rData.iCommand;
fTree.Grp := rData.Group;
//Scripts
fTree.Rslt := rData.ScrResult;
fTree.Scnme := rData.ScrName;
fTree.Sccod := rData.ScrCode;
fTree.Sctyp := rData.ScrType;
Result := True;
Finally
Modified := True;
End;
end;
Function aXmlopenBorSystem.setopenBorSystemData(pData:popenBorSystem):Boolean;
Var
r1Data : ropenBorSystem;
Begin
Try
r1Data := pData2openBorSystemrData(pData);
Result := setopenBorSystemData(r1Data);
Except
Result := false;
End;
End;
Function aXmlopenBorSystem.setopenBorSystemData(rData:ropenBorSystem):Boolean;
Var
i : integer;
Found : Boolean;
begin
Try
i := 0;
Result := False;
if fopenBorSystem <> nil then
while i < fopenBorSystem.Count do Begin
If rData.id = fopenBorSystem.TopenBorSystem[i].id then Begin
Result := setopenBorSystemData(i,rData);
i:= fopenBorSystem.Count;
Found := True;
End;
inc(i);
End;
If Found = false then
addopenBorSystemData(rData);
Except
Result := false;
End;
End;
Function aXmlopenBorSystem.setopenBorSystemData(xmlID:Integer;rData:ropenBorSystem):Boolean;
begin
Try
Result := False;
fopenBorSystem.TopenBorSystem[xmlID].id := rData.id;
fopenBorSystem.TopenBorSystem[xmlID].gd := rData.gd;
fopenBorSystem.TopenBorSystem[xmlID].title := rData.title;
fopenBorSystem.TopenBorSystem[xmlID].dscrp := EncodeString(rData.dscrp);
fopenBorSystem.TopenBorSystem[xmlID].htyp := rData.htyp;
fopenBorSystem.TopenBorSystem[xmlID].vald := rData.vald;
fopenBorSystem.TopenBorSystem[xmlID].lgth := rData.lgth;
fopenBorSystem.TopenBorSystem[xmlID].usd := rData.usd;
fopenBorSystem.TopenBorSystem[xmlID].avar := rData.avar;
fopenBorSystem.TopenBorSystem[xmlID].Mltp := rData.Multiple;
fopenBorSystem.TopenBorSystem[xmlID].Icmd := rData.iCommand;
fopenBorSystem.TopenBorSystem[xmlID].Grp := rData.Group;
//Scripts
fopenBorSystem.TopenBorSystem[xmlID].Rslt := rData.ScrResult;
fopenBorSystem.TopenBorSystem[xmlID].Scnme := rData.ScrName;
fopenBorSystem.TopenBorSystem[xmlID].Sccod := EncodeString(rData.ScrCode);
fopenBorSystem.TopenBorSystem[xmlID].Sctyp := rData.ScrType;
Modified := True;
Result := True;
Except
Result := False;
End;
End;
function aXmlopenBorSystem.setopenBorSystemDataViagd(rData: ropenBorSystem): Boolean;
Var
i : integer;
Found : Boolean;
begin
Try
i := 0;
Result := False;
if fopenBorSystem <> nil then
while i < fopenBorSystem.Count do Begin
If rData.gd = fopenBorSystem.TopenBorSystem[i].gd then Begin
Result := setopenBorSystemData(i,rData);
i:= fopenBorSystem.Count;
Found := True;
End;
inc(i);
End;
If Found = false then
addopenBorSystemData(rData);
Except
Result := false;
End;
end;
Function aXmlopenBorSystem.delopenBorSystemData(pData:popenBorSystem):Boolean;
Var
r1Data : ropenBorSystem;
Begin
Try
r1Data := pData2openBorSystemrData(pData);
Result := delopenBorSystemData(r1Data);
Except
Result := false;
End;
End;
Function aXmlopenBorSystem.delopenBorSystemData(rData:ropenBorSystem):Boolean;
Var
i : integer;
begin
Try
i := 0;
if fopenBorSystem <> nil then
while i < fopenBorSystem.Count do Begin
If rData.id = fopenBorSystem.TopenBorSystem[i].id then Begin
fopenBorSystem.Delete(i);
i:= fopenBorSystem.Count;
Modified := True;
End;
inc(i);
End;
Result := true;
Except
Result := false;
End;
End;
Function aXmlopenBorSystem.delopenBorSystemData(ItemID:Integer):Boolean;
Var
i : integer;
begin
Try
i := 0;
if fopenBorSystem <> nil then
while i < fopenBorSystem.Count do Begin
If ItemID = fopenBorSystem.TopenBorSystem[i].id then Begin
fopenBorSystem.Delete(i);
i:= fopenBorSystem.Count;
Modified := True;
End;
inc(i);
End;
Result := true;
Except
Result := false;
End;
End;
function aXmlopenBorSystem.getopenBorSystemData(xmlID: Integer): ropenBorSystem;
Var
i : Integer;
Begin
Try
Try
fData.id := fopenBorSystem.TopenBorSystem[xmlID].id;
Except
fData.id := -1;
End;
Try
fData.gd := fopenBorSystem.TopenBorSystem[xmlID].gd;
Except
fData.gd := '';
End;
Try
fData.title := fopenBorSystem.TopenBorSystem[xmlID].title;
Except
fData.title := '';
End;
Try
fData.dscrp := DecodeStringStr(fopenBorSystem.TopenBorSystem[xmlID].dscrp);
Except
fData.dscrp := '';
End;
Try
fData.htyp := fopenBorSystem.TopenBorSystem[xmlID].htyp;
Except
fData.htyp := -1;
End;
Try
fData.vald := fopenBorSystem.TopenBorSystem[xmlID].vald;
Except
fData.vald := '';
End;
Try
fData.lgth := fopenBorSystem.TopenBorSystem[xmlID].lgth;
Except
fData.lgth := '';
End;
Try
fData.usd := fopenBorSystem.TopenBorSystem[xmlID].usd;
Except
fData.usd := '';
End;
Try
fData.avar := fopenBorSystem.TopenBorSystem[xmlID].avar;
Except
fData.avar := '';
End;
Try
fData.Multiple := fopenBorSystem.TopenBorSystem[xmlID].Mltp;
Except
fData.Multiple := -1;
End;
Try
fData.iCommand := fopenBorSystem.TopenBorSystem[xmlID].Icmd;
Except
fData.iCommand := -1;
End;
//Script
Try
fData.ScrResult := fopenBorSystem.TopenBorSystem[xmlID].Rslt;
Except
fData.ScrResult := '';
End;
Try
fData.ScrName := fopenBorSystem.TopenBorSystem[xmlID].Scnme;
Except
fData.ScrName := '';
End;
Try
fData.ScrCode := DecodeStringStr(fopenBorSystem.TopenBorSystem[xmlID].Sccod);
Except
fData.ScrCode := '';
End;
Try
if fopenBorSystem.TopenBorSystem[xmlID] <> nil then
fData.ScrType := fopenBorSystem.TopenBorSystem[xmlID].Sctyp;
Except
fData.ScrType := -1;
End;
Try
fData.Group := fopenBorSystem.TopenBorSystem[xmlID].Grp;
Except
fData.Group := 'none';
End;
Finally
Result := fData;
End;
end;
function aXmlopenBorSystem.getopenBorSystemDataViaID(ItemID: Integer): ropenBorSystem;
Var
i : integer;
rData : ropenBorSystem;
begin
Try
rData := clearopenBorSystemrData(rData);
i := 0;
if fopenBorSystem <> nil then
while i < fopenBorSystem.Count do Begin
If ItemID = fopenBorSystem.TopenBorSystem[i].id then Begin
rData := getopenBorSystemData(i);
i:= fopenBorSystem.Count;
End else
inc(i);
End;
Finally
Result := rData;
end;
end;
function aXmlopenBorSystem.getopenBorSystemDataViagd(gd: wideString): ropenBorSystem;
Var
i : integer;
rData : ropenBorSystem;
begin
Try
i := 0;
if fopenBorSystem <> nil then
while i < fopenBorSystem.Count do Begin
If gd = fopenBorSystem.TopenBorSystem[i].gd then Begin
rData := getopenBorSystemData(i);
i:= fopenBorSystem.Count;
End else
inc(i);
End;
Finally
Result := rData;
end;
end;
function aXmlopenBorSystem.getopenBorSystemNew: ropenBorSystem;
Var
ropenBorSystemData : ropenBorSystem;
//udtGUID : TGUID;
//lResult : longint;
Begin
ropenBorSystemData := clearopenBorSystemrData(ropenBorSystemData);
ropenBorSystemData.id := getHighestopenBorSystemID + 1;
//lResult := CoCreateGuid(udtGUID);
ropenBorSystemData.gd := CreateGuid;
Result := ropenBorSystemData;
end;
function aXmlopenBorSystem.clearopenBorSystemrData(rData: ropenBorSystem): ropenBorSystem;
Var
ropenBorSystemData : ropenBorSystem;
Begin
ropenBorSystemData.id := -1;
ropenBorSystemData.gd := '';
ropenBorSystemData.title := '';
ropenBorSystemData.dscrp := '';
ropenBorSystemData.htyp := -1;
ropenBorSystemData.vald := '';
ropenBorSystemData.lgth := '';
ropenBorSystemData.usd := '';
ropenBorSystemData.avar := '';
ropenBorSystemData.hasCommand := false;
ropenBorSystemData.Multiple := -1;
ropenBorSystemData.iCommand := -1;
//Script
ropenBorSystemData.ScrResult := '';
ropenBorSystemData.ScrName := '';
ropenBorSystemData.ScrCode := '';
ropenBorSystemData.ScrType := -1;
Result := ropenBorSystemData;
end;
Function aXmlopenBorSystem.pData2openBorSystemrData(pData:popenBorSystem):ropenBorSystem;
Var
rData : ropenBorSystem;
begin
Try
rData.id := pData.id;
rData.gd := pData.gd;
rData.title := pData.title;
rData.dscrp := pData.dscrp;
rData.htyp := pData.htyp;
rData.vald := pData.vald;
rData.lgth := pData.lgth;
rData.usd := pData.usd;
rData.avar := pData.avar;
rData.hasCommand := pData.hasCommand;
rData.Multiple := pData.Multiple;
rData.iCommand := pData.iCommand;
//New
rData.Group := pData.Group;
//Script
rData.ScrResult := pData.ScrResult;
rData.ScrName := pData.ScrName;
rData.ScrCode := pData.ScrCode;
rData.ScrType := pData.ScrType;
Finally
Result := rData;
End;
End;
Function aXmlopenBorSystem.getHighestopenBorSystemID:Integer;
Var
i, j : Integer;
Begin
Try
j := 0;
try
if fopenBorSystem <> nil then
For i := 0 to fopenBorSystem.Count -1 do Begin
if j < fopenBorSystem.TopenBorSystem[i].id then
j := fopenBorSystem.TopenBorSystem[i].id;
End;
except
end;
Finally
Result := j;
End;
End;
Function aXmlopenBorSystem.getopenBorSystemXmlID(pData:popenBorSystem):Integer;
Var
r1Data : ropenBorSystem;
Begin
Try
r1Data := pData2openBorSystemrData(pData);
Result := getopenBorSystemXmlID(r1Data);
Except
Result := -1;
End;
End;
Function aXmlopenBorSystem.getopenBorSystemXmlID(rData:ropenBorSystem):Integer;
Var
i, j : integer;
begin
Try
i := 0;
j := -1;
if fopenBorSystem <> nil then
while i < fopenBorSystem.Count do Begin
If rData.id = fopenBorSystem.TopenBorSystem[i].id then Begin
j := i;
i:= fopenBorSystem.Count;
End;
inc(i);
End;
Finally
Result := j;
End;
End;
constructor aXmlopenBorSystem.Create(xmlFile:String);
begin
If FileExists(xmlFile) then Begin
Try
fopenBorSystem := LoadTopenBorSystemList(xmlFile)
Except
fopenBorSystem := NewTopenBorSystemList;
End
End Else
fopenBorSystem := NewTopenBorSystemList;
Modified := False;
end;
destructor aXmlopenBorSystem.Destroy;
begin
inherited Destroy;
end;
function aXmlopenBorSystem.SavetoFile(xmlFile:String): Boolean;
Var
aList : TStringList;
begin
Try
aList := TStringList.Create;
aList.Text := fopenBorSystem.XML;
If FileExists(xmlFile) then
DeleteFile(xmlFile);
While verifyXml(xmlFile) = false do
aList.SaveToFile(xmlFile);
aList.Free;
Result := True;
Modified := False;
Except
Result := False;
end;
end;
{//This is more of TTC specific Function
Function aXmlopenBorSystem.SavetoZip:Boolean;
Var
s : String;
begin
Try
Result := True;
//If ckbxSave.Checked = true then
If fopenBorSystem <> nil then Begin
//Form1.setZipOptions(1);
//s := Form1.tmp +'\openBorSystem.xml';
SavetoFile(s);
//ZZAddFile(s,'openBorSystem.xml',Form1.ZipMaster1);
If FileExists(s) then
DeleteFile(s);
Modified := False;
End;
except
Result := False;
end;
End;
//This is more of TTC specific feature
Function aXmlopenBorSystem.loadFromZip:openBorSystem;
Var
s : String;
ax : aXmlopenBorSystem;
Begin
Try
//s := Form1.tmp +'\openBorSystem.xml';
If FileExists(s) then
DeleteFile(s);
//ZZExtractFile('openBorSystem.xml',s,Form1.ZipMaster1);
ax := aXmlopenBorSystem.Create(s);
If FileExists(s) then
DeleteFile(s);
Modified := False;
Result := ax;
Except
Result := ax;
End;
End;}
//This Function automatically gets called when saving!
//It returns a Ture Value If the XML file is Valid
Function aXmlopenBorSystem.verifyXml(aFileName:String):Boolean;
Var
tmpXML : IXMLTopenBorSystemDefList;
Begin
Try
If FileExists(aFileName) then Begin
tmpXML := LoadTopenBorSystemList(aFileName);
Result := True;
If tmpXML <> nil then
tmpXML := nil;
End Else
Result := False;
Except
Result := False;
If tmpXML <> nil then
tmpXML := nil;
End;
End;
procedure aXmlopenBorSystem.importFromFile(EntitySystemFile: String;asType:Integer);
Var
listData : tstringlist;
i : Integer;
s, title, variables : string;
rData : ropenBorSystem;
begin
if FileExists(EntitySystemFile) then Begin
listData := TStringList.Create;
listData.LoadFromFile(EntitySystemFile);
for i := 0 to listData.Count -1 do Begin
s := listData.Strings[i];
s := strClearAll(s);
title := s;
variables := s;
StringDelete2End(title,' ');
StringDeleteUp2(variables,' ');
StringReplace(variables,'{',',');
StringReplace(variables,'}','');
variables := strClearStart(variables);
variables := strClearEnd(variables);
//StringReplace(variables,' ','');
//Add to xml
rData := getopenBorSystemNew;
rData.title := title;
rData.avar := variables;
rData.htyp := asType;
addopenBorSystemData(rData);
end;
listData.Free;
end;
end;
function aXmlopenBorSystem.getGroupList(
glossaryType: integer): TStringList;
Var
listData : TStringList;
i : integer;
s : string;
rData : ropenBorSystem;
begin
listData := TStringList.Create;
listData.Sorted := true;
listData.Duplicates := dupIgnore;
for i := 0 to fopenBorSystem.Count -1 do Begin
if fopenBorSystem.TopenBorSystem[i].Htyp = glossaryType then Begin
//rData := getopenBorSystemData(i);
//if rData.htyp = glossaryType then Begin
try
s := fopenBorSystem.TopenBorSystem[i].Grp;
except
s := '';
end;
listData.Add(s);
end;
end;
result := listData;
end;
end.