Commit 2c54a33b6a05e15d5d1b751f823f70788c2fbbbf

Authored by anderson.peterle@previdencia.gov.br
1 parent d92773ea
Exists in master

Retirada do coletor automático do Projeto.

git-svn-id: http://svn.softwarepublico.gov.br/svn/cacic/cacic/trunk/agente-windows@952 fecfc0c7-e812-0410-ae72-849f08638ee7
col_patr/LibXmlParser.pas
@@ -1,2728 +0,0 @@ @@ -1,2728 +0,0 @@
1 -(**  
2 -===============================================================================================  
3 -Name : LibXmlParser  
4 -===============================================================================================  
5 -Project : All Projects  
6 -===============================================================================================  
7 -Subject : Progressive XML Parser for all types of XML Files  
8 -===============================================================================================  
9 -Author : Stefan Heymann  
10 - Eschenweg 3  
11 - 72076 Tübingen  
12 - GERMANY  
13 -  
14 -E-Mail: stefan@destructor.de  
15 -URL: www.destructor.de  
16 -===============================================================================================  
17 -Source, Legals ("Licence")  
18 ---------------------------  
19 -The official site to get this parser is http://www.destructor.de/  
20 -  
21 -Usage and Distribution of this Source Code is ruled by the  
22 -"Destructor.de Source code Licence" (DSL) which comes with this file or  
23 -can be downloaded at http://www.destructor.de/  
24 -  
25 -IN SHORT: Usage and distribution of this source code is free.  
26 - You use it completely on your own risk.  
27 -  
28 -Postcardware  
29 -------------  
30 -If you like this code, please send a postcard of your city to my above address.  
31 -===============================================================================================  
32 -!!! All parts of this code which are not finished or not conforming exactly to  
33 - the XmlSpec are marked with three exclamation marks  
34 -  
35 --!- Parts where the parser may be able to detect errors in the document's syntax are  
36 - marked with the dash-exlamation mark-dash sequence.  
37 -===============================================================================================  
38 -Terminology:  
39 -------------  
40 -- Start: Start of a buffer part  
41 -- Final: End (last character) of a buffer part  
42 -- DTD: Document Type Definition  
43 -- DTDc: Document Type Declaration  
44 -- XMLSpec: The current W3C XML Recommendation (version 1.0 as of 1998-02-10), Chapter No.  
45 -- Cur*: Fields concerning the "Current" part passed back by the "Scan" method  
46 -===============================================================================================  
47 -Scanning the XML document  
48 --------------------------  
49 -- Create TXmlParser Instance MyXml := TXmlParser.Create;  
50 -- Load XML Document MyXml.LoadFromFile (Filename);  
51 -- Start Scanning MyXml.StartScan;  
52 -- Scan Loop WHILE MyXml.Scan DO  
53 -- Test for Part Type CASE MyXml.CurPartType OF  
54 -- Handle Parts ... : ;;;  
55 -- Handle Parts ... : ;;;  
56 -- Handle Parts ... : ;;;  
57 - END;  
58 -- Destroy MyXml.Free;  
59 -===============================================================================================  
60 -Loading the XML document  
61 -------------------------  
62 -You can load the XML document from a file with the "LoadFromFile" method.  
63 -It is beyond the scope of this parser to perform HTTP or FTP accesses. If you want your  
64 -application to handle such requests (URLs), you can load the XML via HTTP or FTP or whatever  
65 -protocol and hand over the data buffer using the "LoadFromBuffer" or "SetBuffer" method.  
66 -"LoadFromBuffer" loads the internal buffer of TXmlParser with the given null-terminated  
67 -string, thereby creating a copy of that buffer.  
68 -"SetBuffer" just takes the pointer to another buffer, which means that the given  
69 -buffer pointer must be valid while the document is accessed via TXmlParser.  
70 -===============================================================================================  
71 -Encodings:  
72 -----------  
73 -This XML parser kind of "understands" the following encodings:  
74 -- UTF-8  
75 -- ISO-8859-1  
76 -- Windows-1252  
77 -  
78 -Any flavor of multi-byte characters (and this includes UTF-16) is not supported. Sorry.  
79 -  
80 -Every string which has to be passed to the application passes the virtual method  
81 -"TranslateEncoding" which translates the string from the current encoding (stored in  
82 -"CurEncoding") into the encoding the application wishes to receive.  
83 -The "TranslateEncoding" method that is built into TXmlParser assumes that the application  
84 -wants to receive Windows ANSI (Windows-1252, about the same as ISO-8859-1) and is able  
85 -to convert UTF-8 and ISO-8859-1 encodings.  
86 -For other source and target encodings, you will have to override "TranslateEncoding".  
87 -===============================================================================================  
88 -Buffer Handling  
89 ----------------  
90 -- The document must be loaded completely into a piece of RAM  
91 -- All character positions are referenced by PChar pointers  
92 -- The TXmlParser instance can either "own" the buffer itself (then, FBufferSize is > 0)  
93 - or reference the buffer of another instance or object (then, FBuffersize is 0 and  
94 - FBuffer is not NIL)  
95 -- The Property DocBuffer passes back a pointer to the first byte of the document. If there  
96 - is no document stored (FBuffer is NIL), the DocBuffer returns a pointer to a NULL character.  
97 -===============================================================================================  
98 -Whitespace Handling  
99 --------------------  
100 -The TXmlParser property "PackSpaces" determines how Whitespace is returned in Text Content:  
101 -While PackSpaces is true, all leading and trailing whitespace characters are trimmed of, all  
102 -Whitespace is converted to Space #x20 characters and contiguous Whitespace characters are  
103 -compressed to one.  
104 -If the "Scan" method reports a ptContent part, the application can get the original text  
105 -with all whitespace characters by extracting the characters from "CurStart" to "CurFinal".  
106 -If the application detects an xml:space attribute, it can set "PackSpaces" accordingly or  
107 -use CurStart/CurFinal.  
108 -Please note that TXmlParser does _not_ normalize Line Breaks to single LineFeed characters  
109 -as the XmlSpec requires (XmlSpec 2.11).  
110 -The xml:space attribute is not handled by TXmlParser. This is on behalf of the application.  
111 -===============================================================================================  
112 -Non-XML-Conforming  
113 -------------------  
114 -TXmlParser does not conform 100 % exactly to the XmlSpec:  
115 -- UTF-16 is not supported (XmlSpec 2.2)  
116 - (Workaround: Convert UTF-16 to UTF-8 and hand the buffer over to TXmlParser)  
117 -- As the parser only works with single byte strings, all Unicode characters > 255  
118 - can currently not be handled correctly.  
119 -- Line breaks are not normalized to single Linefeed #x0A characters (XmlSpec 2.11)  
120 - (Workaround: The Application can access the text contents on its own [CurStart, CurFinal],  
121 - thereby applying every normalization it wishes to)  
122 -- The attribute value normalization does not work exactly as defined in the  
123 - Second Edition of the XML 1.0 specification.  
124 -- See also the code parts marked with three consecutive exclamation marks. These are  
125 - parts which are not finished in the current code release.  
126 -  
127 -This list may be incomplete, so it may grow if I get to know any other points.  
128 -As work on the parser proceeds, this list may also shrink.  
129 -===============================================================================================  
130 -Things Todo  
131 ------------  
132 -- Introduce a new event/callback which is called when there is an unresolvable  
133 - entity or character reference  
134 -- Support Unicode  
135 -- Use Streams instead of reading the whole XML into memory  
136 -===============================================================================================  
137 -Change History, Version numbers  
138 --------------------------------  
139 -The Date is given in ISO Year-Month-Day (YYYY-MM-DD) order.  
140 -Versions are counted from 1.0.0 beginning with the version from 2000-03-16.  
141 -Unreleased versions don't get a version number.  
142 -  
143 -Date Author Version Changes  
144 ------------------------------------------------------------------------------------------------  
145 -2000-03-16 HeySt 1.0.0 Start  
146 -2000-03-28 HeySt 1.0.1 Initial Publishing of TXmlParser on the destructor.de Web Site  
147 -2000-03-30 HeySt 1.0.2 TXmlParser.AnalyzeCData: Call "TranslateEncoding" for CurContent  
148 -2000-03-31 HeySt 1.0.3 Deleted the StrPosE function (was not needed anyway)  
149 -2000-04-04 HeySt 1.0.4 TDtdElementRec modified: Start/Final for all Elements;  
150 - Should be backwards compatible.  
151 - AnalyzeDtdc: Set CurPartType to ptDtdc  
152 -2000-04-23 HeySt 1.0.5 New class TObjectList. Eliminated reference to the Delphi 5  
153 - "Contnrs" unit so LibXmlParser is Delphi 4 compatible.  
154 -2000-07-03 HeySt 1.0.6 TNvpNode: Added Constructor  
155 -2000-07-11 HeySt 1.0.7 Removed "Windows" from USES clause  
156 - Added three-exclamation-mark comments for Utf8ToAnsi/AnsiToUtf8  
157 - Added three-exclamation-mark comments for CHR function calls  
158 -2000-07-23 HeySt 1.0.8 TXmlParser.Clear: CurAttr.Clear; EntityStack.Clear;  
159 - (This was not a bug; just defensive programming)  
160 -2000-07-29 HeySt 1.0.9 TNvpList: Added methods: Node(Index), Value(Index), Name(Index);  
161 -2000-10-07 HeySt Introduced Conditional Defines  
162 - Uses Contnrs unit and its TObjectList class again for  
163 - Delphi 5 and newer versions  
164 -2001-01-30 HeySt Introduced Version Numbering  
165 - Made LoadFromFile and LoadFromBuffer BOOLEAN functions  
166 - Introduced FileMode parameter for LoadFromFile  
167 - BugFix: TAttrList.Analyze: Must add CWhitespace to ExtractName call  
168 - Comments worked over  
169 -2001-02-28 HeySt 1.0.10 Completely worked over and tested the UTF-8 functions  
170 - Fixed a bug in TXmlParser.Scan which caused it to start over when it  
171 - was called after the end of scanning, resulting in an endless loop  
172 - TEntityStack is now a TObjectList instead of TList  
173 -2001-07-03 HeySt 1.0.11 Updated Compiler Version IFDEFs for Kylix  
174 -2001-07-11 HeySt 1.0.12 New TCustomXmlScanner component (taken over from LibXmlComps.pas)  
175 -2001-07-14 HeySt 1.0.13 Bugfix TCustomXmlScanner.FOnTranslateEncoding  
176 -2001-10-22 HeySt Don't clear CurName anymore when the parser finds a CDATA section.  
177 -2001-12-03 HeySt 1.0.14 TObjectList.Clear: Make call to INHERITED method (fixes a memory leak)  
178 -2001-12-05 HeySt 1.0.15 TObjectList.Clear: removed call to INHERITED method  
179 - TObjectList.Destroy: Inserted SetCapacity call.  
180 - Reduces need for frequent re-allocation of pointer buffer  
181 - Dedicated to my father, Theodor Heymann  
182 -2002-06-26 HeySt 1.0.16 TXmlParser.Scan: Fixed a bug with PIs whose name is beginning  
183 - with 'xml'. Thanks to Uwe Kamm for submitting this bug.  
184 - The CurEncoding property is now always in uppercase letters (the XML  
185 - spec wants it to be treated case independently so when it's uppercase  
186 - comparisons are faster)  
187 -2002-03-04 HeySt 1.0.17 Included an IFDEF for Delphi 7 (VER150) and Kylix  
188 - There is a new symbol HAS_CONTNRS_UNIT which is used now to  
189 - distinguish between IDEs which come with the Contnrs unit and  
190 - those that don't.  
191 -*)  
192 -  
193 -  
194 -// --- Delphi/Kylix Version Numbers  
195 -// As this is no code, this does not blow up your object or executable code at all  
196 - (*$IFDEF LINUX *)  
197 - (*$DEFINE K1_OR_NEWER *)  
198 - (*$ENDIF *)  
199 -  
200 - (*$IFDEF MSWINDOWS *)  
201 - (*$DEFINE D1_OR_NEWER *)  
202 - (*$IFNDEF VER80 *)  
203 - (*$DEFINE D2_OR_NEWER *)  
204 - (*$IFNDEF VER90 *)  
205 - (*$DEFINE D3_OR_NEWER *)  
206 - (*$IFNDEF VER100 *)  
207 - (*$DEFINE D4_OR_NEWER *)  
208 - (*$IFNDEF VER120 *)  
209 - (*$DEFINE D5_OR_NEWER *)  
210 - (*$IFNDEF VER130 *)  
211 - (*$IFNDEF VER140 *)  
212 - (*$IFNDEF VER150 *)  
213 - If the compiler gets stuck here,  
214 - you are using a compiler version unknown to this code.  
215 - You will probably have to change this code accordingly.  
216 - At first, try to comment out these lines and see what will happen.  
217 - (*$ENDIF *)  
218 - (*$ENDIF *)  
219 - (*$ENDIF *)  
220 - (*$ENDIF *)  
221 - (*$ENDIF *)  
222 - (*$ENDIF *)  
223 - (*$ENDIF *)  
224 - (*$ENDIF *)  
225 -  
226 - (*$IFDEF D5_OR_NEWER *)  
227 - (*$DEFINE HAS_CONTNRS_UNIT *)  
228 - (*$ENDIF *)  
229 -  
230 - (*$IFDEF K1_OR_NEWER *)  
231 - (*$DEFINE HAS_CONTNRS_UNIT *)  
232 - (*$ENDIF *)  
233 -  
234 -  
235 -UNIT LibXmlParser;  
236 -  
237 -INTERFACE  
238 -  
239 -USES  
240 - SysUtils, Classes,  
241 - (*$IFDEF HAS_CONTNRS_UNIT *) // The Contnrs Unit was introduced in Delphi 5  
242 - Contnrs,  
243 - (*$ENDIF*)  
244 - Math;  
245 -  
246 -CONST  
247 - CVersion = '1.0.17'; // This variable will be updated for every release  
248 - // (I hope, I won't forget to do it everytime ...)  
249 -  
250 -TYPE  
251 - TPartType = // --- Document Part Types  
252 - (ptNone, // Nothing  
253 - ptXmlProlog, // XML Prolog XmlSpec 2.8 / 4.3.1  
254 - ptComment, // Comment XmlSpec 2.5  
255 - ptPI, // Processing Instruction XmlSpec 2.6  
256 - ptDtdc, // Document Type Declaration XmlSpec 2.8  
257 - ptStartTag, // Start Tag XmlSpec 3.1  
258 - ptEmptyTag, // Empty-Element Tag XmlSpec 3.1  
259 - ptEndTag, // End Tag XmlSpec 3.1  
260 - ptContent, // Text Content between Tags  
261 - ptCData); // CDATA Section XmlSpec 2.7  
262 -  
263 - TDtdElemType = // --- DTD Elements  
264 - (deElement, // !ELEMENT declaration  
265 - deAttList, // !ATTLIST declaration  
266 - deEntity, // !ENTITY declaration  
267 - deNotation, // !NOTATION declaration  
268 - dePI, // PI in DTD  
269 - deComment, // Comment in DTD  
270 - deError); // Error found in the DTD  
271 -  
272 -TYPE  
273 - TAttrList = CLASS;  
274 - TEntityStack = CLASS;  
275 - TNvpList = CLASS;  
276 - TElemDef = CLASS;  
277 - TElemList = CLASS;  
278 - TEntityDef = CLASS;  
279 - TNotationDef = CLASS;  
280 -  
281 - TDtdElementRec = RECORD // --- This Record is returned by the DTD parser callback function  
282 - Start, Final : PChar; // Start/End of the Element's Declaration  
283 - CASE ElementType : TDtdElemType OF // Type of the Element  
284 - deElement, // <!ELEMENT>  
285 - deAttList : (ElemDef : TElemDef); // <!ATTLIST>  
286 - deEntity : (EntityDef : TEntityDef); // <!ENTITY>  
287 - deNotation : (NotationDef : TNotationDef); // <!NOTATION>  
288 - dePI : (Target : PChar; // <?PI ?>  
289 - Content : PChar;  
290 - AttrList : TAttrList);  
291 - deError : (Pos : PChar); // Error  
292 - // deComment : ((No additional fields here)); // <!-- Comment -->  
293 - END;  
294 -  
295 - TXmlParser = CLASS // --- Internal Properties and Methods  
296 - PROTECTED  
297 - FBuffer : PChar; // NIL if there is no buffer available  
298 - FBufferSize : INTEGER; // 0 if the buffer is not owned by the Document instance  
299 - FSource : STRING; // Name of Source of document. Filename for Documents loaded with LoadFromFile  
300 -  
301 - FXmlVersion : STRING; // XML version from Document header. Default is '1.0'  
302 - FEncoding : STRING; // Encoding from Document header. Default is 'UTF-8'  
303 - FStandalone : BOOLEAN; // Standalone declaration from Document header. Default is 'yes'  
304 - FRootName : STRING; // Name of the Root Element (= DTD name)  
305 - FDtdcFinal : PChar; // Pointer to the '>' character terminating the DTD declaration  
306 -  
307 - FNormalize : BOOLEAN; // If true: Pack Whitespace and don't return empty contents  
308 - EntityStack : TEntityStack; // Entity Stack for Parameter and General Entities  
309 - FCurEncoding : STRING; // Current Encoding during parsing (always uppercase)  
310 -  
311 - PROCEDURE AnalyzeProlog; // Analyze XML Prolog or Text Declaration  
312 - PROCEDURE AnalyzeComment (Start : PChar; VAR Final : PChar); // Analyze Comments  
313 - PROCEDURE AnalyzePI (Start : PChar; VAR Final : PChar); // Analyze Processing Instructions (PI)  
314 - PROCEDURE AnalyzeDtdc; // Analyze Document Type Declaration  
315 - PROCEDURE AnalyzeDtdElements (Start : PChar; VAR Final : PChar); // Analyze DTD declarations  
316 - PROCEDURE AnalyzeTag; // Analyze Start/End/Empty-Element Tags  
317 - PROCEDURE AnalyzeCData; // Analyze CDATA Sections  
318 - PROCEDURE AnalyzeText (VAR IsDone : BOOLEAN); // Analyze Text Content between Tags  
319 - PROCEDURE AnalyzeElementDecl (Start : PChar; VAR Final : PChar);  
320 - PROCEDURE AnalyzeAttListDecl (Start : PChar; VAR Final : PChar);  
321 - PROCEDURE AnalyzeEntityDecl (Start : PChar; VAR Final : PChar);  
322 - PROCEDURE AnalyzeNotationDecl (Start : PChar; VAR Final : PChar);  
323 -  
324 - PROCEDURE PushPE (VAR Start : PChar);  
325 - PROCEDURE ReplaceCharacterEntities (VAR Str : STRING);  
326 - PROCEDURE ReplaceParameterEntities (VAR Str : STRING);  
327 - PROCEDURE ReplaceGeneralEntities (VAR Str : STRING);  
328 -  
329 - FUNCTION GetDocBuffer : PChar; // Returns FBuffer or a pointer to a NUL char if Buffer is empty  
330 -  
331 - PUBLIC // --- Document Properties  
332 - PROPERTY XmlVersion : STRING READ FXmlVersion; // XML version from the Document Prolog  
333 - PROPERTY Encoding : STRING READ FEncoding; // Document Encoding from Prolog  
334 - PROPERTY Standalone : BOOLEAN READ FStandalone; // Standalone Declaration from Prolog  
335 - PROPERTY RootName : STRING READ FRootName; // Name of the Root Element  
336 - PROPERTY Normalize : BOOLEAN READ FNormalize WRITE FNormalize; // True if Content is to be normalized  
337 - PROPERTY Source : STRING READ FSource; // Name of Document Source (Filename)  
338 - PROPERTY DocBuffer : PChar READ GetDocBuffer; // Returns document buffer  
339 - PUBLIC // --- DTD Objects  
340 - Elements : TElemList; // Elements: List of TElemDef (contains Attribute Definitions)  
341 - Entities : TNvpList; // General Entities: List of TEntityDef  
342 - ParEntities : TNvpList; // Parameter Entities: List of TEntityDef  
343 - Notations : TNvpList; // Notations: List of TNotationDef  
344 - PUBLIC  
345 - CONSTRUCTOR Create;  
346 - DESTRUCTOR Destroy; OVERRIDE;  
347 -  
348 - // --- Document Handling  
349 - FUNCTION LoadFromFile (Filename : STRING;  
350 - FileMode : INTEGER = fmOpenRead OR fmShareDenyNone) : BOOLEAN;  
351 - // Loads Document from given file  
352 - FUNCTION LoadFromBuffer (Buffer : PChar) : BOOLEAN; // Loads Document from another buffer  
353 - PROCEDURE SetBuffer (Buffer : PChar); // References another buffer  
354 - PROCEDURE Clear; // Clear Document  
355 -  
356 - PUBLIC  
357 - // --- Scanning through the document  
358 - CurPartType : TPartType; // Current Type  
359 - CurName : STRING; // Current Name  
360 - CurContent : STRING; // Current Normalized Content  
361 - CurStart : PChar; // Current First character  
362 - CurFinal : PChar; // Current Last character  
363 - CurAttr : TAttrList; // Current Attribute List  
364 - PROPERTY CurEncoding : STRING READ FCurEncoding; // Current Encoding  
365 - PROCEDURE StartScan;  
366 - FUNCTION Scan : BOOLEAN;  
367 -  
368 - // --- Events / Callbacks  
369 - FUNCTION LoadExternalEntity (SystemId, PublicId,  
370 - Notation : STRING) : TXmlParser; VIRTUAL;  
371 - FUNCTION TranslateEncoding (CONST Source : STRING) : STRING; VIRTUAL;  
372 - PROCEDURE DtdElementFound (DtdElementRec : TDtdElementRec); VIRTUAL;  
373 - END;  
374 -  
375 - TValueType = // --- Attribute Value Type  
376 - (vtNormal, // Normal specified Attribute  
377 - vtImplied, // #IMPLIED attribute value  
378 - vtFixed, // #FIXED attribute value  
379 - vtDefault); // Attribute value from default value in !ATTLIST declaration  
380 -  
381 - TAttrDefault = // --- Attribute Default Type  
382 - (adDefault, // Normal default value  
383 - adRequired, // #REQUIRED attribute  
384 - adImplied, // #IMPLIED attribute  
385 - adFixed); // #FIXED attribute  
386 -  
387 - TAttrType = // --- Type of attribute  
388 - (atUnknown, // Unknown type  
389 - atCData, // Character data only  
390 - atID, // ID  
391 - atIdRef, // ID Reference  
392 - atIdRefs, // Several ID References, separated by Whitespace  
393 - atEntity, // Name of an unparsed Entity  
394 - atEntities, // Several unparsed Entity names, separated by Whitespace  
395 - atNmToken, // Name Token  
396 - atNmTokens, // Several Name Tokens, separated by Whitespace  
397 - atNotation, // A selection of Notation names (Unparsed Entity)  
398 - atEnumeration); // Enumeration  
399 -  
400 - TElemType = // --- Element content type  
401 - (etEmpty, // Element is always empty  
402 - etAny, // Element can have any mixture of PCDATA and any elements  
403 - etChildren, // Element must contain only elements  
404 - etMixed); // Mixed PCDATA and elements  
405 -  
406 - (*$IFDEF HAS_CONTNRS_UNIT *)  
407 - TObjectList = Contnrs.TObjectList; // Re-Export this identifier  
408 - (*$ELSE *)  
409 - TObjectList = CLASS (TList)  
410 - DESTRUCTOR Destroy; OVERRIDE;  
411 - PROCEDURE Delete (Index : INTEGER);  
412 - PROCEDURE Clear; OVERRIDE;  
413 - END;  
414 - (*$ENDIF *)  
415 -  
416 - TNvpNode = CLASS // Name-Value Pair Node  
417 - Name : STRING;  
418 - Value : STRING;  
419 - CONSTRUCTOR Create (TheName : STRING = ''; TheValue : STRING = '');  
420 - END;  
421 -  
422 - TNvpList = CLASS (TObjectList) // Name-Value Pair List  
423 - PROCEDURE Add (Node : TNvpNode);  
424 - FUNCTION Node (Name : STRING) : TNvpNode; OVERLOAD;  
425 - FUNCTION Node (Index : INTEGER) : TNvpNode; OVERLOAD;  
426 - FUNCTION Value (Name : STRING) : STRING; OVERLOAD;  
427 - FUNCTION Value (Index : INTEGER) : STRING; OVERLOAD;  
428 - FUNCTION Name (Index : INTEGER) : STRING;  
429 - END;  
430 -  
431 - TAttr = CLASS (TNvpNode) // Attribute of a Start-Tag or Empty-Element-Tag  
432 - ValueType : TValueType;  
433 - AttrType : TAttrType;  
434 - END;  
435 -  
436 - TAttrList = CLASS (TNvpList) // List of Attributes  
437 - PROCEDURE Analyze (Start : PChar; VAR Final : PChar);  
438 - END;  
439 -  
440 - TEntityStack = CLASS (TObjectList) // Stack where current position is stored before parsing entities  
441 - PROTECTED  
442 - Owner : TXmlParser;  
443 - PUBLIC  
444 - CONSTRUCTOR Create (TheOwner : TXmlParser);  
445 - PROCEDURE Push (LastPos : PChar); OVERLOAD;  
446 - PROCEDURE Push (Instance : TObject; LastPos : PChar); OVERLOAD;  
447 - FUNCTION Pop : PChar; // Returns next char or NIL if EOF is reached. Frees Instance.  
448 - END;  
449 -  
450 - TAttrDef = CLASS (TNvpNode) // Represents a <!ATTLIST Definition. "Value" is the default value  
451 - TypeDef : STRING; // Type definition from the DTD  
452 - Notations : STRING; // Notation List, separated by pipe symbols '|'  
453 - AttrType : TAttrType; // Attribute Type  
454 - DefaultType : TAttrDefault; // Default Type  
455 - END;  
456 -  
457 - TElemDef = CLASS (TNvpList) // Represents a <!ELEMENT Definition. Is a list of TAttrDef-Nodes  
458 - Name : STRING; // Element name  
459 - ElemType : TElemType; // Element type  
460 - Definition : STRING; // Element definition from DTD  
461 - END;  
462 -  
463 - TElemList = CLASS (TObjectList) // List of TElemDef nodes  
464 - FUNCTION Node (Name : STRING) : TElemDef;  
465 - PROCEDURE Add (Node : TElemDef);  
466 - END;  
467 -  
468 - TEntityDef = CLASS (TNvpNode) // Represents a <!ENTITY Definition.  
469 - SystemId : STRING;  
470 - PublicId : STRING;  
471 - NotationName : STRING;  
472 - END;  
473 -  
474 - TNotationDef = CLASS (TNvpNode) // Represents a <!NOTATION Definition. Value is the System ID  
475 - PublicId : STRING;  
476 - END;  
477 -  
478 - TCharset = SET OF CHAR;  
479 -  
480 -  
481 -CONST  
482 - CWhitespace = [#32, #9, #13, #10]; // Whitespace characters (XmlSpec 2.3)  
483 - CLetter = [#$41..#$5A, #$61..#$7A, #$C0..#$D6, #$D8..#$F6, #$F8..#$FF];  
484 - CDigit = [#$30..#$39];  
485 - CNameChar = CLetter + CDigit + ['.', '-', '_', ':', #$B7];  
486 - CNameStart = CLetter + ['_', ':'];  
487 - CQuoteChar = ['"', ''''];  
488 - CPubidChar = [#32, ^M, ^J, #9, 'a'..'z', 'A'..'Z', '0'..'9',  
489 - '-', '''', '(', ')', '+', ',', '.', '/', ':',  
490 - '=', '?', ';', '!', '*', '#', '@', '$', '_', '%'];  
491 -  
492 - CDStart = '<![CDATA[';  
493 - CDEnd = ']]>';  
494 -  
495 - // --- Name Constants for the above enumeration types  
496 - CPartType_Name : ARRAY [TPartType] OF STRING =  
497 - ('', 'XML Prolog', 'Comment', 'PI',  
498 - 'DTD Declaration', 'Start Tag', 'Empty Tag', 'End Tag',  
499 - 'Text', 'CDATA');  
500 - CValueType_Name : ARRAY [TValueType] OF STRING = ('Normal', 'Implied', 'Fixed', 'Default');  
501 - CAttrDefault_Name : ARRAY [TAttrDefault] OF STRING = ('Default', 'Required', 'Implied', 'Fixed');  
502 - CElemType_Name : ARRAY [TElemType] OF STRING = ('Empty', 'Any', 'Childs only', 'Mixed');  
503 - CAttrType_Name : ARRAY [TAttrType] OF STRING = ('Unknown', 'CDATA',  
504 - 'ID', 'IDREF', 'IDREFS',  
505 - 'ENTITY', 'ENTITIES',  
506 - 'NMTOKEN', 'NMTOKENS',  
507 - 'Notation', 'Enumeration');  
508 -  
509 -FUNCTION ConvertWs (Source: STRING; PackWs: BOOLEAN) : STRING; // Convert WS to spaces #x20  
510 -PROCEDURE SetStringSF (VAR S : STRING; BufferStart, BufferFinal : PChar); // SetString by Start/Final of buffer  
511 -FUNCTION StrSFPas (Start, Finish : PChar) : STRING; // Convert buffer part to Pascal string  
512 -FUNCTION TrimWs (Source : STRING) : STRING; // Trim Whitespace  
513 -  
514 -FUNCTION AnsiToUtf8 (Source : ANSISTRING) : STRING; // Convert Win-1252 to UTF-8  
515 -FUNCTION Utf8ToAnsi (Source : STRING; UnknownChar : CHAR = '¿') : ANSISTRING; // Convert UTF-8 to Win-1252  
516 -  
517 -  
518 -(*  
519 -===============================================================================================  
520 -TCustomXmlScanner event based component wrapper for TXmlParser  
521 -===============================================================================================  
522 -*)  
523 -  
524 -TYPE  
525 - TCustomXmlScanner = CLASS;  
526 - TXmlPrologEvent = PROCEDURE (Sender : TObject; XmlVersion, Encoding: STRING; Standalone : BOOLEAN) OF OBJECT;  
527 - TCommentEvent = PROCEDURE (Sender : TObject; Comment : STRING) OF OBJECT;  
528 - TPIEvent = PROCEDURE (Sender : TObject; Target, Content: STRING; Attributes : TAttrList) OF OBJECT;  
529 - TDtdEvent = PROCEDURE (Sender : TObject; RootElementName : STRING) OF OBJECT;  
530 - TStartTagEvent = PROCEDURE (Sender : TObject; TagName : STRING; Attributes : TAttrList) OF OBJECT;  
531 - TEndTagEvent = PROCEDURE (Sender : TObject; TagName : STRING) OF OBJECT;  
532 - TContentEvent = PROCEDURE (Sender : TObject; Content : STRING) OF OBJECT;  
533 - TElementEvent = PROCEDURE (Sender : TObject; ElemDef : TElemDef) OF OBJECT;  
534 - TEntityEvent = PROCEDURE (Sender : TObject; EntityDef : TEntityDef) OF OBJECT;  
535 - TNotationEvent = PROCEDURE (Sender : TObject; NotationDef : TNotationDef) OF OBJECT;  
536 - TErrorEvent = PROCEDURE (Sender : TObject; ErrorPos : PChar) OF OBJECT;  
537 - TExternalEvent = PROCEDURE (Sender : TObject; SystemId, PublicId, NotationId : STRING;  
538 - VAR Result : TXmlParser) OF OBJECT;  
539 - TEncodingEvent = FUNCTION (Sender : TObject; CurrentEncoding, Source : STRING) : STRING OF OBJECT;  
540 -  
541 -  
542 - TCustomXmlScanner = CLASS (TComponent)  
543 - PROTECTED  
544 - FXmlParser : TXmlParser;  
545 - FOnXmlProlog : TXmlPrologEvent;  
546 - FOnComment : TCommentEvent;  
547 - FOnPI : TPIEvent;  
548 - FOnDtdRead : TDtdEvent;  
549 - FOnStartTag : TStartTagEvent;  
550 - FOnEmptyTag : TStartTagEvent;  
551 - FOnEndTag : TEndTagEvent;  
552 - FOnContent : TContentEvent;  
553 - FOnCData : TContentEvent;  
554 - FOnElement : TElementEvent;  
555 - FOnAttList : TElementEvent;  
556 - FOnEntity : TEntityEvent;  
557 - FOnNotation : TNotationEvent;  
558 - FOnDtdError : TErrorEvent;  
559 - FOnLoadExternal : TExternalEvent;  
560 - FOnTranslateEncoding : TEncodingEvent;  
561 - FStopParser : BOOLEAN;  
562 - FUNCTION GetNormalize : BOOLEAN;  
563 - PROCEDURE SetNormalize (Value : BOOLEAN);  
564 -  
565 - PROCEDURE WhenXmlProlog(XmlVersion, Encoding: STRING; Standalone : BOOLEAN); VIRTUAL;  
566 - PROCEDURE WhenComment (Comment : STRING); VIRTUAL;  
567 - PROCEDURE WhenPI (Target, Content: STRING; Attributes : TAttrList); VIRTUAL;  
568 - PROCEDURE WhenDtdRead (RootElementName : STRING); VIRTUAL;  
569 - PROCEDURE WhenStartTag (TagName : STRING; Attributes : TAttrList); VIRTUAL;  
570 - PROCEDURE WhenEmptyTag (TagName : STRING; Attributes : TAttrList); VIRTUAL;  
571 - PROCEDURE WhenEndTag (TagName : STRING); VIRTUAL;  
572 - PROCEDURE WhenContent (Content : STRING); VIRTUAL;  
573 - PROCEDURE WhenCData (Content : STRING); VIRTUAL;  
574 - PROCEDURE WhenElement (ElemDef : TElemDef); VIRTUAL;  
575 - PROCEDURE WhenAttList (ElemDef : TElemDef); VIRTUAL;  
576 - PROCEDURE WhenEntity (EntityDef : TEntityDef); VIRTUAL;  
577 - PROCEDURE WhenNotation (NotationDef : TNotationDef); VIRTUAL;  
578 - PROCEDURE WhenDtdError (ErrorPos : PChar); VIRTUAL;  
579 -  
580 - PUBLIC  
581 - CONSTRUCTOR Create (AOwner: TComponent); OVERRIDE;  
582 - DESTRUCTOR Destroy; OVERRIDE;  
583 -  
584 - PROCEDURE LoadFromFile (Filename : TFilename); // Load XML Document from file  
585 - PROCEDURE LoadFromBuffer (Buffer : PChar); // Load XML Document from buffer  
586 - PROCEDURE SetBuffer (Buffer : PChar); // Refer to Buffer  
587 - FUNCTION GetFilename : TFilename;  
588 -  
589 - PROCEDURE Execute; // Perform scanning  
590 -  
591 - PROTECTED  
592 - PROPERTY XmlParser : TXmlParser READ FXmlParser;  
593 - PROPERTY StopParser : BOOLEAN READ FStopParser WRITE FStopParser;  
594 - PROPERTY Filename : TFilename READ GetFilename WRITE LoadFromFile;  
595 - PROPERTY Normalize : BOOLEAN READ GetNormalize WRITE SetNormalize;  
596 - PROPERTY OnXmlProlog : TXmlPrologEvent READ FOnXmlProlog WRITE FOnXmlProlog;  
597 - PROPERTY OnComment : TCommentEvent READ FOnComment WRITE FOnComment;  
598 - PROPERTY OnPI : TPIEvent READ FOnPI WRITE FOnPI;  
599 - PROPERTY OnDtdRead : TDtdEvent READ FOnDtdRead WRITE FOnDtdRead;  
600 - PROPERTY OnStartTag : TStartTagEvent READ FOnStartTag WRITE FOnStartTag;  
601 - PROPERTY OnEmptyTag : TStartTagEvent READ FOnEmptyTag WRITE FOnEmptyTag;  
602 - PROPERTY OnEndTag : TEndTagEvent READ FOnEndTag WRITE FOnEndTag;  
603 - PROPERTY OnContent : TContentEvent READ FOnContent WRITE FOnContent;  
604 - PROPERTY OnCData : TContentEvent READ FOnCData WRITE FOnCData;  
605 - PROPERTY OnElement : TElementEvent READ FOnElement WRITE FOnElement;  
606 - PROPERTY OnAttList : TElementEvent READ FOnAttList WRITE FOnAttList;  
607 - PROPERTY OnEntity : TEntityEvent READ FOnEntity WRITE FOnEntity;  
608 - PROPERTY OnNotation : TNotationEvent READ FOnNotation WRITE FOnNotation;  
609 - PROPERTY OnDtdError : TErrorEvent READ FOnDtdError WRITE FOnDtdError;  
610 - PROPERTY OnLoadExternal : TExternalEvent READ FOnLoadExternal WRITE FOnLoadExternal;  
611 - PROPERTY OnTranslateEncoding : TEncodingEvent READ FOnTranslateEncoding WRITE FOnTranslateEncoding;  
612 - END;  
613 -  
614 -(*  
615 -===============================================================================================  
616 -IMPLEMENTATION  
617 -===============================================================================================  
618 -*)  
619 -  
620 -IMPLEMENTATION  
621 -  
622 -  
623 -(*  
624 -===============================================================================================  
625 -Unicode and UTF-8 stuff  
626 -===============================================================================================  
627 -*)  
628 -  
629 -CONST  
630 - // --- Character Translation Table for Unicode <-> Win-1252  
631 - WIN1252_UNICODE : ARRAY [$00..$FF] OF WORD = (  
632 - $0000, $0001, $0002, $0003, $0004, $0005, $0006, $0007, $0008, $0009,  
633 - $000A, $000B, $000C, $000D, $000E, $000F, $0010, $0011, $0012, $0013,  
634 - $0014, $0015, $0016, $0017, $0018, $0019, $001A, $001B, $001C, $001D,  
635 - $001E, $001F, $0020, $0021, $0022, $0023, $0024, $0025, $0026, $0027,  
636 - $0028, $0029, $002A, $002B, $002C, $002D, $002E, $002F, $0030, $0031,  
637 - $0032, $0033, $0034, $0035, $0036, $0037, $0038, $0039, $003A, $003B,  
638 - $003C, $003D, $003E, $003F, $0040, $0041, $0042, $0043, $0044, $0045,  
639 - $0046, $0047, $0048, $0049, $004A, $004B, $004C, $004D, $004E, $004F,  
640 - $0050, $0051, $0052, $0053, $0054, $0055, $0056, $0057, $0058, $0059,  
641 - $005A, $005B, $005C, $005D, $005E, $005F, $0060, $0061, $0062, $0063,  
642 - $0064, $0065, $0066, $0067, $0068, $0069, $006A, $006B, $006C, $006D,  
643 - $006E, $006F, $0070, $0071, $0072, $0073, $0074, $0075, $0076, $0077,  
644 - $0078, $0079, $007A, $007B, $007C, $007D, $007E, $007F,  
645 -  
646 - $20AC, $0081, $201A, $0192, $201E, $2026, $2020, $2021, $02C6, $2030,  
647 - $0160, $2039, $0152, $008D, $017D, $008F, $0090, $2018, $2019, $201C,  
648 - $201D, $2022, $2013, $2014, $02DC, $2122, $0161, $203A, $0153, $009D,  
649 - $017E, $0178, $00A0, $00A1, $00A2, $00A3, $00A4, $00A5, $00A6, $00A7,  
650 - $00A8, $00A9, $00AA, $00AB, $00AC, $00AD, $00AE, $00AF, $00B0, $00B1,  
651 - $00B2, $00B3, $00B4, $00B5, $00B6, $00B7, $00B8, $00B9, $00BA, $00BB,  
652 - $00BC, $00BD, $00BE, $00BF, $00C0, $00C1, $00C2, $00C3, $00C4, $00C5,  
653 - $00C6, $00C7, $00C8, $00C9, $00CA, $00CB, $00CC, $00CD, $00CE, $00CF,  
654 - $00D0, $00D1, $00D2, $00D3, $00D4, $00D5, $00D6, $00D7, $00D8, $00D9,  
655 - $00DA, $00DB, $00DC, $00DD, $00DE, $00DF, $00E0, $00E1, $00E2, $00E3,  
656 - $00E4, $00E5, $00E6, $00E7, $00E8, $00E9, $00EA, $00EB, $00EC, $00ED,  
657 - $00EE, $00EF, $00F0, $00F1, $00F2, $00F3, $00F4, $00F5, $00F6, $00F7,  
658 - $00F8, $00F9, $00FA, $00FB, $00FC, $00FD, $00FE, $00FF);  
659 -  
660 -(* UTF-8 (somewhat simplified)  
661 - -----  
662 - Character Range Byte sequence  
663 - --------------- -------------------------- (x=Bits from original character)  
664 - $0000..$007F 0xxxxxxx  
665 - $0080..$07FF 110xxxxx 10xxxxxx  
666 - $8000..$FFFF 1110xxxx 10xxxxxx 10xxxxxx  
667 -  
668 - Example  
669 - --------  
670 - Transforming the Unicode character U+00E4 LATIN SMALL LETTER A WITH DIAERESIS ("ä"):  
671 -  
672 - ISO-8859-1, Decimal 228  
673 - Win1252, Hex $E4  
674 - ANSI Bin 1110 0100  
675 - abcd efgh  
676 -  
677 - UTF-8 Binary 1100xxab 10cdefgh  
678 - Binary 11000011 10100100  
679 - Hex $C3 $A4  
680 - Decimal 195 164  
681 - ANSI Ã ¤ *)  
682 -  
683 -  
684 -FUNCTION AnsiToUtf8 (Source : ANSISTRING) : STRING;  
685 - (* Converts the given Windows ANSI (Win1252) String to UTF-8. *)  
686 -VAR  
687 - I : INTEGER; // Loop counter  
688 - U : WORD; // Current Unicode value  
689 - Len : INTEGER; // Current real length of "Result" string  
690 -BEGIN  
691 - SetLength (Result, Length (Source) * 3); // Worst case  
692 - Len := 0;  
693 - FOR I := 1 TO Length (Source) DO BEGIN  
694 - U := WIN1252_UNICODE [ORD (Source [I])];  
695 - CASE U OF  
696 - $0000..$007F : BEGIN  
697 - INC (Len);  
698 - Result [Len] := CHR (U);  
699 - END;  
700 - $0080..$07FF : BEGIN  
701 - INC (Len);  
702 - Result [Len] := CHR ($C0 OR (U SHR 6));  
703 - INC (Len);  
704 - Result [Len] := CHR ($80 OR (U AND $3F));  
705 - END;  
706 - $0800..$FFFF : BEGIN  
707 - INC (Len);  
708 - Result [Len] := CHR ($E0 OR (U SHR 12));  
709 - INC (Len);  
710 - Result [Len] := CHR ($80 OR ((U SHR 6) AND $3F));  
711 - INC (Len);  
712 - Result [Len] := CHR ($80 OR (U AND $3F));  
713 - END;  
714 - END;  
715 - END;  
716 - SetLength (Result, Len);  
717 -END;  
718 -  
719 -  
720 -FUNCTION Utf8ToAnsi (Source : STRING; UnknownChar : CHAR = '¿') : ANSISTRING;  
721 - (* Converts the given UTF-8 String to Windows ANSI (Win-1252).  
722 - If a character can not be converted, the "UnknownChar" is inserted. *)  
723 -VAR  
724 - SourceLen : INTEGER; // Length of Source string  
725 - I, K : INTEGER;  
726 - A : BYTE; // Current ANSI character value  
727 - U : WORD;  
728 - Ch : CHAR; // Dest char  
729 - Len : INTEGER; // Current real length of "Result" string  
730 -BEGIN  
731 - SourceLen := Length (Source);  
732 - SetLength (Result, SourceLen); // Enough room to live  
733 - Len := 0;  
734 - I := 1;  
735 - WHILE I <= SourceLen DO BEGIN  
736 - A := ORD (Source [I]);  
737 - IF A < $80 THEN BEGIN // Range $0000..$007F  
738 - INC (Len);  
739 - Result [Len] := Source [I];  
740 - INC (I);  
741 - END  
742 - ELSE BEGIN // Determine U, Inc I  
743 - IF (A AND $E0 = $C0) AND (I < SourceLen) THEN BEGIN // Range $0080..$07FF  
744 - U := (WORD (A AND $1F) SHL 6) OR (ORD (Source [I+1]) AND $3F);  
745 - INC (I, 2);  
746 - END  
747 - ELSE IF (A AND $F0 = $E0) AND (I < SourceLen-1) THEN BEGIN // Range $0800..$FFFF  
748 - U := (WORD (A AND $0F) SHL 12) OR  
749 - (WORD (ORD (Source [I+1]) AND $3F) SHL 6) OR  
750 - ( ORD (Source [I+2]) AND $3F);  
751 - INC (I, 3);  
752 - END  
753 - ELSE BEGIN // Unknown/unsupported  
754 - INC (I);  
755 - FOR K := 7 DOWNTO 0 DO  
756 - IF A AND (1 SHL K) = 0 THEN BEGIN  
757 - INC (I, (A SHR (K+1))-1);  
758 - BREAK;  
759 - END;  
760 - U := WIN1252_UNICODE [ORD (UnknownChar)];  
761 - END;  
762 - Ch := UnknownChar; // Retrieve ANSI char  
763 - FOR A := $00 TO $FF DO  
764 - IF WIN1252_UNICODE [A] = U THEN BEGIN  
765 - Ch := CHR (A);  
766 - BREAK;  
767 - END;  
768 - INC (Len);  
769 - Result [Len] := Ch;  
770 - END;  
771 - END;  
772 - SetLength (Result, Len);  
773 -END;  
774 -  
775 -  
776 -(*  
777 -===============================================================================================  
778 -"Special" Helper Functions  
779 -  
780 -Don't ask me why. But including these functions makes the parser *DRAMATICALLY* faster  
781 -on my K6-233 machine. You can test it yourself just by commenting them out.  
782 -They do exactly the same as the Assembler routines defined in SysUtils.  
783 -(This is where you can see how great the Delphi compiler really is. The compiled code is  
784 -faster than hand-coded assembler!)  
785 -===============================================================================================  
786 ---> Just move this line below the StrScan function --> *)  
787 -  
788 -  
789 -FUNCTION StrPos (CONST Str, SearchStr : PChar) : PChar;  
790 - // Same functionality as SysUtils.StrPos  
791 -VAR  
792 - First : CHAR;  
793 - Len : INTEGER;  
794 -BEGIN  
795 - First := SearchStr^;  
796 - Len := StrLen (SearchStr);  
797 - Result := Str;  
798 - REPEAT  
799 - IF Result^ = First THEN  
800 - IF StrLComp (Result, SearchStr, Len) = 0 THEN BREAK;  
801 - IF Result^ = #0 THEN BEGIN  
802 - Result := NIL;  
803 - BREAK;  
804 - END;  
805 - INC (Result);  
806 - UNTIL FALSE;  
807 -END;  
808 -  
809 -  
810 -FUNCTION StrScan (CONST Start : PChar; CONST Ch : CHAR) : PChar;  
811 - // Same functionality as SysUtils.StrScan  
812 -BEGIN  
813 - Result := Start;  
814 - WHILE Result^ <> Ch DO BEGIN  
815 - IF Result^ = #0 THEN BEGIN  
816 - Result := NIL;  
817 - EXIT;  
818 - END;  
819 - INC (Result);  
820 - END;  
821 -END;  
822 -  
823 -  
824 -(*  
825 -===============================================================================================  
826 -Helper Functions  
827 -===============================================================================================  
828 -*)  
829 -  
830 -FUNCTION DelChars (Source : STRING; CharsToDelete : TCharset) : STRING;  
831 - // Delete all "CharsToDelete" from the string  
832 -VAR  
833 - I : INTEGER;  
834 -BEGIN  
835 - Result := Source;  
836 - FOR I := Length (Result) DOWNTO 1 DO  
837 - IF Result [I] IN CharsToDelete THEN  
838 - Delete (Result, I, 1);  
839 -END;  
840 -  
841 -  
842 -FUNCTION TrimWs (Source : STRING) : STRING;  
843 - // Trimms off Whitespace characters from both ends of the string  
844 -VAR  
845 - I : INTEGER;  
846 -BEGIN  
847 - // --- Trim Left  
848 - I := 1;  
849 - WHILE (I <= Length (Source)) AND (Source [I] IN CWhitespace) DO  
850 - INC (I);  
851 - Result := Copy (Source, I, MaxInt);  
852 -  
853 - // --- Trim Right  
854 - I := Length (Result);  
855 - WHILE (I > 1) AND (Result [I] IN CWhitespace) DO  
856 - DEC (I);  
857 - Delete (Result, I+1, Length (Result)-I);  
858 -END;  
859 -  
860 -  
861 -FUNCTION ConvertWs (Source: STRING; PackWs: BOOLEAN) : STRING;  
862 - // Converts all Whitespace characters to the Space #x20 character  
863 - // If "PackWs" is true, contiguous Whitespace characters are packed to one  
864 -VAR  
865 - I : INTEGER;  
866 -BEGIN  
867 - Result := Source;  
868 - FOR I := Length (Result) DOWNTO 1 DO  
869 - IF (Result [I] IN CWhitespace) THEN  
870 - IF PackWs AND (I > 1) AND (Result [I-1] IN CWhitespace)  
871 - THEN Delete (Result, I, 1)  
872 - ELSE Result [I] := #32;  
873 -END;  
874 -  
875 -  
876 -PROCEDURE SetStringSF (VAR S : STRING; BufferStart, BufferFinal : PChar);  
877 -BEGIN  
878 - SetString (S, BufferStart, BufferFinal-BufferStart+1);  
879 -END;  
880 -  
881 -  
882 -FUNCTION StrLPas (Start : PChar; Len : INTEGER) : STRING;  
883 -BEGIN  
884 - SetString (Result, Start, Len);  
885 -END;  
886 -  
887 -  
888 -FUNCTION StrSFPas (Start, Finish : PChar) : STRING;  
889 -BEGIN  
890 - SetString (Result, Start, Finish-Start+1);  
891 -END;  
892 -  
893 -  
894 -FUNCTION StrScanE (CONST Source : PChar; CONST CharToScanFor : CHAR) : PChar;  
895 - // If "CharToScanFor" is not found, StrScanE returns the last char of the  
896 - // buffer instead of NIL  
897 -BEGIN  
898 - Result := StrScan (Source, CharToScanFor);  
899 - IF Result = NIL THEN  
900 - Result := StrEnd (Source)-1;  
901 -END;  
902 -  
903 -  
904 -PROCEDURE ExtractName (Start : PChar; Terminators : TCharset; VAR Final : PChar);  
905 - (* Extracts the complete Name beginning at "Start".  
906 - It is assumed that the name is contained in Markup, so the '>' character is  
907 - always a Termination.  
908 - Start: IN Pointer to first char of name. Is always considered to be valid  
909 - Terminators: IN Characters which terminate the name  
910 - Final: OUT Pointer to last char of name *)  
911 -BEGIN  
912 - Final := Start+1;  
913 - Include (Terminators, #0);  
914 - Include (Terminators, '>');  
915 - WHILE NOT (Final^ IN Terminators) DO  
916 - INC (Final);  
917 - DEC (Final);  
918 -END;  
919 -  
920 -  
921 -PROCEDURE ExtractQuote (Start : PChar; VAR Content : STRING; VAR Final : PChar);  
922 - (* Extract a string which is contained in single or double Quotes.  
923 - Start: IN Pointer to opening quote  
924 - Content: OUT The quoted string  
925 - Final: OUT Pointer to closing quote *)  
926 -BEGIN  
927 - Final := StrScan (Start+1, Start^);  
928 - IF Final = NIL THEN BEGIN  
929 - Final := StrEnd (Start+1)-1;  
930 - SetString (Content, Start+1, Final-Start);  
931 - END  
932 - ELSE  
933 - SetString (Content, Start+1, Final-1-Start);  
934 -END;  
935 -  
936 -  
937 -(*  
938 -===============================================================================================  
939 -TEntityStackNode  
940 -This Node is pushed to the "Entity Stack" whenever the parser parses entity replacement text.  
941 -The "Instance" field holds the Instance pointer of an External Entity buffer. When it is  
942 -popped, the Instance is freed.  
943 -The "Encoding" field holds the name of the Encoding. External Parsed Entities may have  
944 -another encoding as the document entity (XmlSpec 4.3.3). So when there is an "<?xml" PI  
945 -found in the stream (= Text Declaration at the beginning of external parsed entities), the  
946 -Encoding found there is used for the External Entity (is assigned to TXmlParser.CurEncoding)  
947 -Default Encoding is for the Document Entity is UTF-8. It is assumed that External Entities  
948 -have the same Encoding as the Document Entity, unless they carry a Text Declaration.  
949 -===============================================================================================  
950 -*)  
951 -  
952 -TYPE  
953 - TEntityStackNode = CLASS  
954 - Instance : TObject;  
955 - Encoding : STRING;  
956 - LastPos : PChar;  
957 - END;  
958 -  
959 -(*  
960 -===============================================================================================  
961 -TEntityStack  
962 -For nesting of Entities.  
963 -When there is an entity reference found in the data stream, the corresponding entity  
964 -definition is searched and the current position is pushed to this stack.  
965 -From then on, the program scans the entitiy replacement text as if it were normal content.  
966 -When the parser reaches the end of an entity, the current position is popped off the  
967 -stack again.  
968 -===============================================================================================  
969 -*)  
970 -  
971 -CONSTRUCTOR TEntityStack.Create (TheOwner : TXmlParser);  
972 -BEGIN  
973 - INHERITED Create;  
974 - Owner := TheOwner;  
975 -END;  
976 -  
977 -  
978 -PROCEDURE TEntityStack.Push (LastPos : PChar);  
979 -BEGIN  
980 - Push (NIL, LastPos);  
981 -END;  
982 -  
983 -  
984 -PROCEDURE TEntityStack.Push (Instance : TObject; LastPos : PChar);  
985 -VAR  
986 - ESN : TEntityStackNode;  
987 -BEGIN  
988 - ESN := TEntityStackNode.Create;  
989 - ESN.Instance := Instance;  
990 - ESN.Encoding := Owner.FCurEncoding; // Save current Encoding  
991 - ESN.LastPos := LastPos;  
992 - Add (ESN);  
993 -END;  
994 -  
995 -  
996 -FUNCTION TEntityStack.Pop : PChar;  
997 -VAR  
998 - ESN : TEntityStackNode;  
999 -BEGIN  
1000 - IF Count > 0 THEN BEGIN  
1001 - ESN := TEntityStackNode (Items [Count-1]);  
1002 - Result := ESN.LastPos;  
1003 - IF ESN.Instance <> NIL THEN  
1004 - ESN.Instance.Free;  
1005 - IF ESN.Encoding <> '' THEN  
1006 - Owner.FCurEncoding := ESN.Encoding; // Restore current Encoding  
1007 - Delete (Count-1);  
1008 - END  
1009 - ELSE  
1010 - Result := NIL;  
1011 -END;  
1012 -  
1013 -  
1014 -(*  
1015 -===============================================================================================  
1016 -TExternalID  
1017 ------------  
1018 -XmlSpec 4.2.2: ExternalID ::= 'SYSTEM' S SystemLiteral |  
1019 - 'PUBLIC' S PubidLiteral S SystemLiteral  
1020 -XmlSpec 4.7: PublicID ::= 'PUBLIC' S PubidLiteral  
1021 -SystemLiteral and PubidLiteral are quoted  
1022 -===============================================================================================  
1023 -*)  
1024 -  
1025 -TYPE  
1026 - TExternalID = CLASS  
1027 - PublicId : STRING;  
1028 - SystemId : STRING;  
1029 - Final : PChar;  
1030 - CONSTRUCTOR Create (Start : PChar);  
1031 - END;  
1032 -  
1033 -CONSTRUCTOR TExternalID.Create (Start : PChar);  
1034 -BEGIN  
1035 - INHERITED Create;  
1036 - Final := Start;  
1037 - IF StrLComp (Start, 'SYSTEM', 6) = 0 THEN BEGIN  
1038 - WHILE NOT (Final^ IN (CQuoteChar + [#0, '>', '['])) DO INC (Final);  
1039 - IF NOT (Final^ IN CQuoteChar) THEN EXIT;  
1040 - ExtractQuote (Final, SystemID, Final);  
1041 - END  
1042 - ELSE IF StrLComp (Start, 'PUBLIC', 6) = 0 THEN BEGIN  
1043 - WHILE NOT (Final^ IN (CQuoteChar + [#0, '>', '['])) DO INC (Final);  
1044 - IF NOT (Final^ IN CQuoteChar) THEN EXIT;  
1045 - ExtractQuote (Final, PublicID, Final);  
1046 - INC (Final);  
1047 - WHILE NOT (Final^ IN (CQuoteChar + [#0, '>', '['])) DO INC (Final);  
1048 - IF NOT (Final^ IN CQuoteChar) THEN EXIT;  
1049 - ExtractQuote (Final, SystemID, Final);  
1050 - END;  
1051 -END;  
1052 -  
1053 -  
1054 -(*  
1055 -===============================================================================================  
1056 -TXmlParser  
1057 -===============================================================================================  
1058 -*)  
1059 -  
1060 -CONSTRUCTOR TXmlParser.Create;  
1061 -BEGIN  
1062 - INHERITED Create;  
1063 - FBuffer := NIL;  
1064 - FBufferSize := 0;  
1065 - Elements := TElemList.Create;  
1066 - Entities := TNvpList.Create;  
1067 - ParEntities := TNvpList.Create;  
1068 - Notations := TNvpList.Create;  
1069 - CurAttr := TAttrList.Create;  
1070 - EntityStack := TEntityStack.Create (Self);  
1071 - Clear;  
1072 -END;  
1073 -  
1074 -  
1075 -DESTRUCTOR TXmlParser.Destroy;  
1076 -BEGIN  
1077 - Clear;  
1078 - Elements.Free;  
1079 - Entities.Free;  
1080 - ParEntities.Free;  
1081 - Notations.Free;  
1082 - CurAttr.Free;  
1083 - EntityStack.Free;  
1084 - INHERITED Destroy;  
1085 -END;  
1086 -  
1087 -  
1088 -PROCEDURE TXmlParser.Clear;  
1089 - // Free Buffer and clear all object attributes  
1090 -BEGIN  
1091 - IF (FBufferSize > 0) AND (FBuffer <> NIL) THEN  
1092 - FreeMem (FBuffer);  
1093 - FBuffer := NIL;  
1094 - FBufferSize := 0;  
1095 - FSource := '';  
1096 - FXmlVersion := '';  
1097 - FEncoding := '';  
1098 - FStandalone := FALSE;  
1099 - FRootName := '';  
1100 - FDtdcFinal := NIL;  
1101 - FNormalize := TRUE;  
1102 - Elements.Clear;  
1103 - Entities.Clear;  
1104 - ParEntities.Clear;  
1105 - Notations.Clear;  
1106 - CurAttr.Clear;  
1107 - EntityStack.Clear;  
1108 -END;  
1109 -  
1110 -  
1111 -FUNCTION TXmlParser.LoadFromFile (Filename : STRING; FileMode : INTEGER = fmOpenRead OR fmShareDenyNone) : BOOLEAN;  
1112 - // Loads Document from given file  
1113 - // Returns TRUE if successful  
1114 -VAR  
1115 - f : FILE;  
1116 - ReadIn : INTEGER;  
1117 - OldFileMode : INTEGER;  
1118 -BEGIN  
1119 - Result := FALSE;  
1120 - Clear;  
1121 -  
1122 - // --- Open File  
1123 - OldFileMode := SYSTEM.FileMode;  
1124 - TRY  
1125 - SYSTEM.FileMode := FileMode;  
1126 - TRY  
1127 - AssignFile (f, Filename);  
1128 - Reset (f, 1);  
1129 - EXCEPT  
1130 - EXIT;  
1131 - END;  
1132 -  
1133 - TRY  
1134 - // --- Allocate Memory  
1135 - TRY  
1136 - FBufferSize := Filesize (f) + 1;  
1137 - GetMem (FBuffer, FBufferSize);  
1138 - EXCEPT  
1139 - Clear;  
1140 - EXIT;  
1141 - END;  
1142 -  
1143 - // --- Read File  
1144 - TRY  
1145 - BlockRead (f, FBuffer^, FBufferSize, ReadIn);  
1146 - (FBuffer+ReadIn)^ := #0; // NULL termination  
1147 - EXCEPT  
1148 - Clear;  
1149 - EXIT;  
1150 - END;  
1151 - FINALLY  
1152 - CloseFile (f);  
1153 - END;  
1154 -  
1155 - FSource := Filename;  
1156 - Result := TRUE;  
1157 -  
1158 - FINALLY  
1159 - SYSTEM.FileMode := OldFileMode;  
1160 - END;  
1161 -END;  
1162 -  
1163 -  
1164 -FUNCTION TXmlParser.LoadFromBuffer (Buffer : PChar) : BOOLEAN;  
1165 - // Loads Document from another buffer  
1166 - // Returns TRUE if successful  
1167 - // The "Source" property becomes '<MEM>' if successful  
1168 -BEGIN  
1169 - Result := FALSE;  
1170 - Clear;  
1171 - FBufferSize := StrLen (Buffer) + 1;  
1172 - TRY  
1173 - GetMem (FBuffer, FBufferSize);  
1174 - EXCEPT  
1175 - Clear;  
1176 - EXIT;  
1177 - END;  
1178 - StrCopy (FBuffer, Buffer);  
1179 - FSource := '<MEM>';  
1180 - Result := TRUE;  
1181 -END;  
1182 -  
1183 -  
1184 -PROCEDURE TXmlParser.SetBuffer (Buffer : PChar); // References another buffer  
1185 -BEGIN  
1186 - Clear;  
1187 - FBuffer := Buffer;  
1188 - FBufferSize := 0;  
1189 - FSource := '<REFERENCE>';  
1190 -END;  
1191 -  
1192 -  
1193 -//-----------------------------------------------------------------------------------------------  
1194 -// Scanning through the document  
1195 -//-----------------------------------------------------------------------------------------------  
1196 -  
1197 -PROCEDURE TXmlParser.StartScan;  
1198 -BEGIN  
1199 - CurPartType := ptNone;  
1200 - CurName := '';  
1201 - CurContent := '';  
1202 - CurStart := NIL;  
1203 - CurFinal := NIL;  
1204 - CurAttr.Clear;  
1205 - EntityStack.Clear;  
1206 -END;  
1207 -  
1208 -  
1209 -FUNCTION TXmlParser.Scan : BOOLEAN;  
1210 - // Scans the next Part  
1211 - // Returns TRUE if a part could be found, FALSE if there is no part any more  
1212 - //  
1213 - // "IsDone" can be set to FALSE by AnalyzeText in order to go to the next part  
1214 - // if there is no Content due to normalization  
1215 -VAR  
1216 - IsDone : BOOLEAN;  
1217 -BEGIN  
1218 - REPEAT  
1219 - IsDone := TRUE;  
1220 -  
1221 - // --- Start of next Part  
1222 - IF CurStart = NIL  
1223 - THEN CurStart := DocBuffer  
1224 - ELSE CurStart := CurFinal+1;  
1225 - CurFinal := CurStart;  
1226 -  
1227 - // --- End of Document of Pop off a new part from the Entity stack?  
1228 - IF CurStart^ = #0 THEN  
1229 - CurStart := EntityStack.Pop;  
1230 -  
1231 - // --- No Document or End Of Document: Terminate Scan  
1232 - IF (CurStart = NIL) OR (CurStart^ = #0) THEN BEGIN  
1233 - CurStart := StrEnd (DocBuffer);  
1234 - CurFinal := CurStart-1;  
1235 - EntityStack.Clear;  
1236 - Result := FALSE;  
1237 - EXIT;  
1238 - END;  
1239 -  
1240 - IF (StrLComp (CurStart, '<?xml', 5) = 0) AND  
1241 - ((CurStart+5)^ IN CWhitespace) THEN AnalyzeProlog // XML Declaration, Text Declaration  
1242 - ELSE IF StrLComp (CurStart, '<?', 2) = 0 THEN AnalyzePI (CurStart, CurFinal) // PI  
1243 - ELSE IF StrLComp (CurStart, '<!--', 4) = 0 THEN AnalyzeComment (CurStart, CurFinal) // Comment  
1244 - ELSE IF StrLComp (CurStart, '<!DOCTYPE', 9) = 0 THEN AnalyzeDtdc // DTDc  
1245 - ELSE IF StrLComp (CurStart, CDStart, Length (CDStart)) = 0 THEN AnalyzeCdata // CDATA Section  
1246 - ELSE IF StrLComp (CurStart, '<', 1) = 0 THEN AnalyzeTag // Start-Tag, End-Tag, Empty-Element-Tag  
1247 - ELSE AnalyzeText (IsDone); // Text Content  
1248 - UNTIL IsDone;  
1249 - Result := TRUE;  
1250 -END;  
1251 -  
1252 -  
1253 -PROCEDURE TXmlParser.AnalyzeProlog;  
1254 - // Analyze XML Prolog or Text Declaration  
1255 -VAR  
1256 - F : PChar;  
1257 -BEGIN  
1258 - CurAttr.Analyze (CurStart+5, F);  
1259 - IF EntityStack.Count = 0 THEN BEGIN  
1260 - FXmlVersion := CurAttr.Value ('version');  
1261 - FEncoding := CurAttr.Value ('encoding');  
1262 - FStandalone := CurAttr.Value ('standalone') = 'yes';  
1263 - END;  
1264 - CurFinal := StrPos (F, '?>');  
1265 - IF CurFinal <> NIL  
1266 - THEN INC (CurFinal)  
1267 - ELSE CurFinal := StrEnd (CurStart)-1;  
1268 - FCurEncoding := AnsiUpperCase (CurAttr.Value ('encoding'));  
1269 - IF FCurEncoding = '' THEN  
1270 - FCurEncoding := 'UTF-8'; // Default XML Encoding is UTF-8  
1271 - CurPartType := ptXmlProlog;  
1272 - CurName := '';  
1273 - CurContent := '';  
1274 -END;  
1275 -  
1276 -  
1277 -PROCEDURE TXmlParser.AnalyzeComment (Start : PChar; VAR Final : PChar);  
1278 - // Analyze Comments  
1279 -BEGIN  
1280 - Final := StrPos (Start+4, '-->');  
1281 - IF Final = NIL  
1282 - THEN Final := StrEnd (Start)-1  
1283 - ELSE INC (Final, 2);  
1284 - CurPartType := ptComment;  
1285 -END;  
1286 -  
1287 -  
1288 -PROCEDURE TXmlParser.AnalyzePI (Start : PChar; VAR Final : PChar);  
1289 - // Analyze Processing Instructions (PI)  
1290 - // This is also called for Character  
1291 -VAR  
1292 - F : PChar;  
1293 -BEGIN  
1294 - CurPartType := ptPI;  
1295 - Final := StrPos (Start+2, '?>');  
1296 - IF Final = NIL  
1297 - THEN Final := StrEnd (Start)-1  
1298 - ELSE INC (Final);  
1299 - ExtractName (Start+2, CWhitespace + ['?', '>'], F);  
1300 - SetStringSF (CurName, Start+2, F);  
1301 - SetStringSF (CurContent, F+1, Final-2);  
1302 - CurAttr.Analyze (F+1, F);  
1303 -END;  
1304 -  
1305 -  
1306 -PROCEDURE TXmlParser.AnalyzeDtdc;  
1307 - (* Analyze Document Type Declaration  
1308 - doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' (markupdecl | PEReference | S)* ']' S?)? '>'  
1309 - markupdecl ::= elementdecl | AttlistDecl | EntityDecl | NotationDecl | PI | Comment  
1310 - PEReference ::= '%' Name ';'  
1311 -  
1312 - elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'  
1313 - AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'  
1314 - EntityDecl ::= '<!ENTITY' S Name S EntityDef S? '>' |  
1315 - '<!ENTITY' S '%' S Name S PEDef S? '>'  
1316 - NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'  
1317 - PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char* )))? '?>'  
1318 - Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' *)  
1319 -TYPE  
1320 - TPhase = (phName, phDtd, phInternal, phFinishing);  
1321 -VAR  
1322 - Phase : TPhase;  
1323 - F : PChar;  
1324 - ExternalID : TExternalID;  
1325 - ExternalDTD : TXmlParser;  
1326 - DER : TDtdElementRec;  
1327 -BEGIN  
1328 - DER.Start := CurStart;  
1329 - EntityStack.Clear; // Clear stack for Parameter Entities  
1330 - CurPartType := ptDtdc;  
1331 -  
1332 - // --- Don't read DTDc twice  
1333 - IF FDtdcFinal <> NIL THEN BEGIN  
1334 - CurFinal := FDtdcFinal;  
1335 - EXIT;  
1336 - END;  
1337 -  
1338 - // --- Scan DTDc  
1339 - CurFinal := CurStart + 9; // First char after '<!DOCTYPE'  
1340 - Phase := phName;  
1341 - REPEAT  
1342 - CASE CurFinal^ OF  
1343 - '%' : BEGIN  
1344 - PushPE (CurFinal);  
1345 - CONTINUE;  
1346 - END;  
1347 - #0 : IF EntityStack.Count = 0 THEN  
1348 - BREAK  
1349 - ELSE BEGIN  
1350 - CurFinal := EntityStack.Pop;  
1351 - CONTINUE;  
1352 - END;  
1353 - '[' : BEGIN  
1354 - Phase := phInternal;  
1355 - AnalyzeDtdElements (CurFinal+1, CurFinal);  
1356 - CONTINUE;  
1357 - END;  
1358 - ']' : Phase := phFinishing;  
1359 - '>' : BREAK;  
1360 - ELSE IF NOT (CurFinal^ IN CWhitespace) THEN BEGIN  
1361 - CASE Phase OF  
1362 - phName : IF (CurFinal^ IN CNameStart) THEN BEGIN  
1363 - ExtractName (CurFinal, CWhitespace + ['[', '>'], F);  
1364 - SetStringSF (FRootName, CurFinal, F);  
1365 - CurFinal := F;  
1366 - Phase := phDtd;  
1367 - END;  
1368 - phDtd : IF (StrLComp (CurFinal, 'SYSTEM', 6) = 0) OR  
1369 - (StrLComp (CurFinal, 'PUBLIC', 6) = 0) THEN BEGIN  
1370 - ExternalID := TExternalID.Create (CurFinal);  
1371 - ExternalDTD := LoadExternalEntity (ExternalId.SystemId, ExternalID.PublicId, '');  
1372 - F := StrPos (ExternalDtd.DocBuffer, '<!');  
1373 - IF F <> NIL THEN  
1374 - AnalyzeDtdElements (F, F);  
1375 - ExternalDTD.Free;  
1376 - CurFinal := ExternalID.Final;  
1377 - ExternalID.Free;  
1378 - END;  
1379 - ELSE BEGIN  
1380 - DER.ElementType := deError;  
1381 - DER.Pos := CurFinal;  
1382 - DER.Final := CurFinal;  
1383 - DtdElementFound (DER);  
1384 - END;  
1385 - END;  
1386 -  
1387 - END;  
1388 - END;  
1389 - INC (CurFinal);  
1390 - UNTIL FALSE;  
1391 -  
1392 - CurPartType := ptDtdc;  
1393 - CurName := '';  
1394 - CurContent := '';  
1395 -  
1396 - // It is an error in the document if "EntityStack" is not empty now  
1397 - IF EntityStack.Count > 0 THEN BEGIN  
1398 - DER.ElementType := deError;  
1399 - DER.Final := CurFinal;  
1400 - DER.Pos := CurFinal;  
1401 - DtdElementFound (DER);  
1402 - END;  
1403 -  
1404 - EntityStack.Clear; // Clear stack for General Entities  
1405 - FDtdcFinal := CurFinal;  
1406 -END;  
1407 -  
1408 -  
1409 -PROCEDURE TXmlParser.AnalyzeDtdElements (Start : PChar; VAR Final : PChar);  
1410 - // Analyze the "Elements" of a DTD contained in the external or  
1411 - // internal DTD subset.  
1412 -VAR  
1413 - DER : TDtdElementRec;  
1414 -BEGIN  
1415 - Final := Start;  
1416 - REPEAT  
1417 - CASE Final^ OF  
1418 - '%' : BEGIN  
1419 - PushPE (Final);  
1420 - CONTINUE;  
1421 - END;  
1422 - #0 : IF EntityStack.Count = 0 THEN  
1423 - BREAK  
1424 - ELSE BEGIN  
1425 - CurFinal := EntityStack.Pop;  
1426 - CONTINUE;  
1427 - END;  
1428 - ']',  
1429 - '>' : BREAK;  
1430 - '<' : IF StrLComp (Final, '<!ELEMENT', 9) = 0 THEN AnalyzeElementDecl (Final, Final)  
1431 - ELSE IF StrLComp (Final, '<!ATTLIST', 9) = 0 THEN AnalyzeAttListDecl (Final, Final)  
1432 - ELSE IF StrLComp (Final, '<!ENTITY', 8) = 0 THEN AnalyzeEntityDecl (Final, Final)  
1433 - ELSE IF StrLComp (Final, '<!NOTATION', 10) = 0 THEN AnalyzeNotationDecl (Final, Final)  
1434 - ELSE IF StrLComp (Final, '<?', 2) = 0 THEN BEGIN // PI in DTD  
1435 - DER.ElementType := dePI;  
1436 - DER.Start := Final;  
1437 - AnalyzePI (Final, Final);  
1438 - DER.Target := PChar (CurName);  
1439 - DER.Content := PChar (CurContent);  
1440 - DER.AttrList := CurAttr;  
1441 - DER.Final := Final;  
1442 - DtdElementFound (DER);  
1443 - END  
1444 - ELSE IF StrLComp (Final, '<!--', 4) = 0 THEN BEGIN // Comment in DTD  
1445 - DER.ElementType := deComment;  
1446 - DER.Start := Final;  
1447 - AnalyzeComment (Final, Final);  
1448 - DER.Final := Final;  
1449 - DtdElementFound (DER);  
1450 - END  
1451 - ELSE BEGIN  
1452 - DER.ElementType := deError;  
1453 - DER.Start := Final;  
1454 - DER.Pos := Final;  
1455 - DER.Final := Final;  
1456 - DtdElementFound (DER);  
1457 - END;  
1458 -  
1459 - END;  
1460 - INC (Final);  
1461 - UNTIL FALSE;  
1462 -END;  
1463 -  
1464 -  
1465 -PROCEDURE TXmlParser.AnalyzeTag;  
1466 - // Analyze Tags  
1467 -VAR  
1468 - S, F : PChar;  
1469 - Attr : TAttr;  
1470 - ElemDef : TElemDef;  
1471 - AttrDef : TAttrDef;  
1472 - I : INTEGER;  
1473 -BEGIN  
1474 - CurPartType := ptStartTag;  
1475 - S := CurStart+1;  
1476 - IF S^ = '/' THEN BEGIN  
1477 - CurPartType := ptEndTag;  
1478 - INC (S);  
1479 - END;  
1480 - ExtractName (S, CWhitespace + ['/'], F);  
1481 - SetStringSF (CurName, S, F);  
1482 - CurAttr.Analyze (F+1, CurFinal);  
1483 - IF CurFinal^ = '/' THEN BEGIN  
1484 - CurPartType := ptEmptyTag;  
1485 - END;  
1486 - CurFinal := StrScanE (CurFinal, '>');  
1487 -  
1488 - // --- Set Default Attribute values for nonexistent attributes  
1489 - IF (CurPartType = ptStartTag) OR (CurPartType = ptEmptyTag) THEN BEGIN  
1490 - ElemDef := Elements.Node (CurName);  
1491 - IF ElemDef <> NIL THEN BEGIN  
1492 - FOR I := 0 TO ElemDef.Count-1 DO BEGIN  
1493 - AttrDef := TAttrDef (ElemDef [I]);  
1494 - Attr := TAttr (CurAttr.Node (AttrDef.Name));  
1495 - IF (Attr = NIL) AND (AttrDef.Value <> '') THEN BEGIN  
1496 - Attr := TAttr.Create (AttrDef.Name, AttrDef.Value);  
1497 - Attr.ValueType := vtDefault;  
1498 - CurAttr.Add (Attr);  
1499 - END;  
1500 - IF Attr <> NIL THEN BEGIN  
1501 - CASE AttrDef.DefaultType OF  
1502 - adDefault : ;  
1503 - adRequired : ; // -!- It is an error in the document if "Attr.Value" is an empty string  
1504 - adImplied : Attr.ValueType := vtImplied;  
1505 - adFixed : BEGIN  
1506 - Attr.ValueType := vtFixed;  
1507 - Attr.Value := AttrDef.Value;  
1508 - END;  
1509 - END;  
1510 - Attr.AttrType := AttrDef.AttrType;  
1511 - END;  
1512 - END;  
1513 - END;  
1514 -  
1515 - // --- Normalize Attribute Values. XmlSpec:  
1516 - // - a character reference is processed by appending the referenced character to the attribute value  
1517 - // - an entity reference is processed by recursively processing the replacement text of the entity  
1518 - // - a whitespace character (#x20, #xD, #xA, #x9) is processed by appending #x20 to the normalized value,  
1519 - // except that only a single #x20 is appended for a "#xD#xA" sequence that is part of an external  
1520 - // parsed entity or the literal entity value of an internal parsed entity  
1521 - // - other characters are processed by appending them to the normalized value  
1522 - // If the declared value is not CDATA, then the XML processor must further process the  
1523 - // normalized attribute value by discarding any leading and trailing space (#x20) characters,  
1524 - // and by replacing sequences of space (#x20) characters by a single space (#x20) character.  
1525 - // All attributes for which no declaration has been read should be treated by a  
1526 - // non-validating parser as if declared CDATA.  
1527 - // !!! The XML 1.0 SE specification is somewhat different here  
1528 - // This code does not conform exactly to this specification  
1529 - FOR I := 0 TO CurAttr.Count-1 DO  
1530 - WITH TAttr (CurAttr [I]) DO BEGIN  
1531 - ReplaceGeneralEntities (Value);  
1532 - ReplaceCharacterEntities (Value);  
1533 - IF (AttrType <> atCData) AND (AttrType <> atUnknown)  
1534 - THEN Value := TranslateEncoding (TrimWs (ConvertWs (Value, TRUE)))  
1535 - ELSE Value := TranslateEncoding (ConvertWs (Value, FALSE));  
1536 - END;  
1537 - END;  
1538 -END;  
1539 -  
1540 -  
1541 -PROCEDURE TXmlParser.AnalyzeCData;  
1542 - // Analyze CDATA Sections  
1543 -BEGIN  
1544 - CurPartType := ptCData;  
1545 - CurFinal := StrPos (CurStart, CDEnd);  
1546 - IF CurFinal = NIL THEN BEGIN  
1547 - CurFinal := StrEnd (CurStart)-1;  
1548 - CurContent := TranslateEncoding (StrPas (CurStart+Length (CDStart)));  
1549 - END  
1550 - ELSE BEGIN  
1551 - SetStringSF (CurContent, CurStart+Length (CDStart), CurFinal-1);  
1552 - INC (CurFinal, Length (CDEnd)-1);  
1553 - CurContent := TranslateEncoding (CurContent);  
1554 - END;  
1555 -END;  
1556 -  
1557 -  
1558 -PROCEDURE TXmlParser.AnalyzeText (VAR IsDone : BOOLEAN);  
1559 - (* Analyzes Text Content between Tags. CurFinal will point to the last content character.  
1560 - Content ends at a '<' character or at the end of the document.  
1561 - Entity References and Character Entity references are resolved.  
1562 - If PackSpaces is TRUE, contiguous Whitespace Characters will be compressed to  
1563 - one Space #x20 character, Whitespace at the beginning and end of content will  
1564 - be trimmed off and content which is or becomes empty is not returned to  
1565 - the application (in this case, "IsDone" is set to FALSE which causes the  
1566 - Scan method to proceed directly to the next part. *)  
1567 -  
1568 - PROCEDURE ProcessEntity;  
1569 - (* Is called if there is an ampsersand '&' character found in the document.  
1570 - IN "CurFinal" points to the ampersand  
1571 - OUT "CurFinal" points to the first character after the semi-colon ';' *)  
1572 - VAR  
1573 - P : PChar;  
1574 - Name : STRING;  
1575 - EntityDef : TEntityDef;  
1576 - ExternalEntity : TXmlParser;  
1577 - BEGIN  
1578 - P := StrScan (CurFinal , ';');  
1579 - IF P <> NIL THEN BEGIN  
1580 - SetStringSF (Name, CurFinal+1, P-1);  
1581 -  
1582 - // Is it a Character Entity?  
1583 - IF (CurFinal+1)^ = '#' THEN BEGIN  
1584 - IF UpCase ((CurFinal+2)^) = 'X' // !!! Can't use "CHR" for Unicode characters > 255:  
1585 - THEN CurContent := CurContent + CHR (StrToIntDef ('$'+Copy (Name, 3, MaxInt), 32))  
1586 - ELSE CurContent := CurContent + CHR (StrToIntDef (Copy (Name, 2, MaxInt), 32));  
1587 - CurFinal := P+1;  
1588 - EXIT;  
1589 - END  
1590 -  
1591 - // Is it a Predefined Entity?  
1592 - ELSE IF Name = 'lt' THEN BEGIN CurContent := CurContent + '<'; CurFinal := P+1; EXIT; END  
1593 - ELSE IF Name = 'gt' THEN BEGIN CurContent := CurContent + '>'; CurFinal := P+1; EXIT; END  
1594 - ELSE IF Name = 'amp' THEN BEGIN CurContent := CurContent + '&'; CurFinal := P+1; EXIT; END  
1595 - ELSE IF Name = 'apos' THEN BEGIN CurContent := CurContent + ''''; CurFinal := P+1; EXIT; END  
1596 - ELSE IF Name = 'quot' THEN BEGIN CurContent := CurContent + '"'; CurFinal := P+1; EXIT; END;  
1597 -  
1598 - // Replace with Entity from DTD  
1599 - EntityDef := TEntityDef (Entities.Node (Name));  
1600 - IF EntityDef <> NIL THEN BEGIN  
1601 - IF EntityDef.Value <> '' THEN BEGIN  
1602 - EntityStack.Push (P+1);  
1603 - CurFinal := PChar (EntityDef.Value);  
1604 - END  
1605 - ELSE BEGIN  
1606 - ExternalEntity := LoadExternalEntity (EntityDef.SystemId, EntityDef.PublicId, EntityDef.NotationName);  
1607 - EntityStack.Push (ExternalEntity, P+1);  
1608 - CurFinal := ExternalEntity.DocBuffer;  
1609 - END;  
1610 - END  
1611 - ELSE BEGIN  
1612 - CurContent := CurContent + Name;  
1613 - CurFinal := P+1;  
1614 - END;  
1615 - END  
1616 - ELSE BEGIN  
1617 - INC (CurFinal);  
1618 - END;  
1619 - END;  
1620 -  
1621 -VAR  
1622 - C : INTEGER;  
1623 -BEGIN  
1624 - CurFinal := CurStart;  
1625 - CurPartType := ptContent;  
1626 - CurContent := '';  
1627 - C := 0;  
1628 - REPEAT  
1629 - CASE CurFinal^ OF  
1630 - '&' : BEGIN  
1631 - CurContent := CurContent + TranslateEncoding (StrLPas (CurFinal-C, C));  
1632 - C := 0;  
1633 - ProcessEntity;  
1634 - CONTINUE;  
1635 - END;  
1636 - #0 : BEGIN  
1637 - IF EntityStack.Count = 0 THEN  
1638 - BREAK  
1639 - ELSE BEGIN  
1640 - CurContent := CurContent + TranslateEncoding (StrLPas (CurFinal-C, C));  
1641 - C := 0;  
1642 - CurFinal := EntityStack.Pop;  
1643 - CONTINUE;  
1644 - END;  
1645 - END;  
1646 - '<' : BREAK;  
1647 - ELSE INC (C);  
1648 - END;  
1649 - INC (CurFinal);  
1650 - UNTIL FALSE;  
1651 - CurContent := CurContent + TranslateEncoding (StrLPas (CurFinal-C, C));  
1652 - DEC (CurFinal);  
1653 -  
1654 - IF FNormalize THEN BEGIN  
1655 - CurContent := ConvertWs (TrimWs (CurContent), TRUE);  
1656 - IsDone := CurContent <> ''; // IsDone will only get FALSE if PackSpaces is TRUE  
1657 - END;  
1658 -END;  
1659 -  
1660 -  
1661 -PROCEDURE TXmlParser.AnalyzeElementDecl (Start : PChar; VAR Final : PChar);  
1662 - (* Parse <!ELEMENT declaration starting at "Start"  
1663 - Final must point to the terminating '>' character  
1664 - XmlSpec 3.2:  
1665 - elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'  
1666 - contentspec ::= 'EMPTY' | 'ANY' | Mixed | children  
1667 - Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' |  
1668 - '(' S? '#PCDATA' S? ')'  
1669 - children ::= (choice | seq) ('?' | '*' | '+')?  
1670 - choice ::= '(' S? cp ( S? '|' S? cp )* S? ')'  
1671 - cp ::= (Name | choice | seq) ('?' | '*' | '+')?  
1672 - seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'  
1673 -  
1674 - More simply:  
1675 - contentspec ::= EMPTY  
1676 - ANY  
1677 - '(#PCDATA)'  
1678 - '(#PCDATA | A | B)*'  
1679 - '(A, B, C)'  
1680 - '(A | B | C)'  
1681 - '(A?, B*, C+),  
1682 - '(A, (B | C | D)* )' *)  
1683 -VAR  
1684 - Element : TElemDef;  
1685 - Elem2 : TElemDef;  
1686 - F : PChar;  
1687 - DER : TDtdElementRec;  
1688 -BEGIN  
1689 - Element := TElemDef.Create;  
1690 - Final := Start + 9;  
1691 - DER.Start := Start;  
1692 - REPEAT  
1693 - IF Final^ = '>' THEN BREAK;  
1694 - IF (Final^ IN CNameStart) AND (Element.Name = '') THEN BEGIN  
1695 - ExtractName (Final, CWhitespace, F);  
1696 - SetStringSF (Element.Name, Final, F);  
1697 - Final := F;  
1698 - F := StrScan (Final+1, '>');  
1699 - IF F = NIL THEN BEGIN  
1700 - Element.Definition := STRING (Final);  
1701 - Final := StrEnd (Final);  
1702 - BREAK;  
1703 - END  
1704 - ELSE BEGIN  
1705 - SetStringSF (Element.Definition, Final+1, F-1);  
1706 - Final := F;  
1707 - BREAK;  
1708 - END;  
1709 - END;  
1710 - INC (Final);  
1711 - UNTIL FALSE;  
1712 - Element.Definition := DelChars (Element.Definition, CWhitespace);  
1713 - ReplaceParameterEntities (Element.Definition);  
1714 - IF Element.Definition = 'EMPTY' THEN Element.ElemType := etEmpty  
1715 - ELSE IF Element.Definition = 'ANY' THEN Element.ElemType := etAny  
1716 - ELSE IF Copy (Element.Definition, 1, 8) = '(#PCDATA' THEN Element.ElemType := etMixed  
1717 - ELSE IF Copy (Element.Definition, 1, 1) = '(' THEN Element.ElemType := etChildren  
1718 - ELSE Element.ElemType := etAny;  
1719 -  
1720 - Elem2 := Elements.Node (Element.Name);  
1721 - IF Elem2 <> NIL THEN  
1722 - Elements.Delete (Elements.IndexOf (Elem2));  
1723 - Elements.Add (Element);  
1724 - Final := StrScanE (Final, '>');  
1725 - DER.ElementType := deElement;  
1726 - DER.ElemDef := Element;  
1727 - DER.Final := Final;  
1728 - DtdElementFound (DER);  
1729 -END;  
1730 -  
1731 -  
1732 -PROCEDURE TXmlParser.AnalyzeAttListDecl (Start : PChar; VAR Final : PChar);  
1733 - (* Parse <!ATTLIST declaration starting at "Start"  
1734 - Final must point to the terminating '>' character  
1735 - XmlSpec 3.3:  
1736 - AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'  
1737 - AttDef ::= S Name S AttType S DefaultDecl  
1738 - AttType ::= StringType | TokenizedType | EnumeratedType  
1739 - StringType ::= 'CDATA'  
1740 - TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | 'ENTITIES' | 'NMTOKEN' | 'NMTOKENS'  
1741 - EnumeratedType ::= NotationType | Enumeration  
1742 - NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'  
1743 - Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'  
1744 - DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S)? AttValue)  
1745 - AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"  
1746 - Examples:  
1747 - <!ATTLIST address  
1748 - A1 CDATA "Default"  
1749 - A2 ID #REQUIRED  
1750 - A3 IDREF #IMPLIED  
1751 - A4 IDREFS #IMPLIED  
1752 - A5 ENTITY #FIXED "&at;&#252;"  
1753 - A6 ENTITIES #REQUIRED  
1754 - A7 NOTATION (WMF | DXF) "WMF"  
1755 - A8 (A | B | C) #REQUIRED> *)  
1756 -TYPE  
1757 - TPhase = (phElementName, phName, phType, phNotationContent, phDefault);  
1758 -VAR  
1759 - Phase : TPhase;  
1760 - F : PChar;  
1761 - ElementName : STRING;  
1762 - ElemDef : TElemDef;  
1763 - AttrDef : TAttrDef;  
1764 - AttrDef2 : TAttrDef;  
1765 - Strg : STRING;  
1766 - DER : TDtdElementRec;  
1767 -BEGIN  
1768 - Final := Start + 9; // The character after <!ATTLIST  
1769 - Phase := phElementName;  
1770 - DER.Start := Start;  
1771 - AttrDef := NIL;  
1772 - ElemDef := NIL;  
1773 - REPEAT  
1774 - IF NOT (Final^ IN CWhitespace) THEN  
1775 - CASE Final^ OF  
1776 - '%' : BEGIN  
1777 - PushPE (Final);  
1778 - CONTINUE;  
1779 - END;  
1780 - #0 : IF EntityStack.Count = 0 THEN  
1781 - BREAK  
1782 - ELSE BEGIN  
1783 - Final := EntityStack.Pop;  
1784 - CONTINUE;  
1785 - END;  
1786 - '>' : BREAK;  
1787 - ELSE CASE Phase OF  
1788 - phElementName : BEGIN  
1789 - ExtractName (Final, CWhitespace + CQuoteChar + ['#'], F);  
1790 - SetStringSF (ElementName, Final, F);  
1791 - Final := F;  
1792 - ElemDef := Elements.Node (ElementName);  
1793 - IF ElemDef = NIL THEN BEGIN  
1794 - ElemDef := TElemDef.Create;  
1795 - ElemDef.Name := ElementName;  
1796 - ElemDef.Definition := 'ANY';  
1797 - ElemDef.ElemType := etAny;  
1798 - Elements.Add (ElemDef);  
1799 - END;  
1800 - Phase := phName;  
1801 - END;  
1802 - phName : BEGIN  
1803 - AttrDef := TAttrDef.Create;  
1804 - ExtractName (Final, CWhitespace + CQuoteChar + ['#'], F);  
1805 - SetStringSF (AttrDef.Name, Final, F);  
1806 - Final := F;  
1807 - AttrDef2 := TAttrDef (ElemDef.Node (AttrDef.Name));  
1808 - IF AttrDef2 <> NIL THEN  
1809 - ElemDef.Delete (ElemDef.IndexOf (AttrDef2));  
1810 - ElemDef.Add (AttrDef);  
1811 - Phase := phType;  
1812 - END;  
1813 - phType : BEGIN  
1814 - IF Final^ = '(' THEN BEGIN  
1815 - F := StrScan (Final+1, ')');  
1816 - IF F <> NIL  
1817 - THEN SetStringSF (AttrDef.TypeDef, Final+1, F-1)  
1818 - ELSE AttrDef.TypeDef := STRING (Final+1);  
1819 - AttrDef.TypeDef := DelChars (AttrDef.TypeDef, CWhitespace);  
1820 - AttrDef.AttrType := atEnumeration;  
1821 - ReplaceParameterEntities (AttrDef.TypeDef);  
1822 - ReplaceCharacterEntities (AttrDef.TypeDef);  
1823 - Phase := phDefault;  
1824 - END  
1825 - ELSE IF StrLComp (Final, 'NOTATION', 8) = 0 THEN BEGIN  
1826 - INC (Final, 8);  
1827 - AttrDef.AttrType := atNotation;  
1828 - Phase := phNotationContent;  
1829 - END  
1830 - ELSE BEGIN  
1831 - ExtractName (Final, CWhitespace+CQuoteChar+['#'], F);  
1832 - SetStringSF (AttrDef.TypeDef, Final, F);  
1833 - IF AttrDef.TypeDef = 'CDATA' THEN AttrDef.AttrType := atCData  
1834 - ELSE IF AttrDef.TypeDef = 'ID' THEN AttrDef.AttrType := atId  
1835 - ELSE IF AttrDef.TypeDef = 'IDREF' THEN AttrDef.AttrType := atIdRef  
1836 - ELSE IF AttrDef.TypeDef = 'IDREFS' THEN AttrDef.AttrType := atIdRefs  
1837 - ELSE IF AttrDef.TypeDef = 'ENTITY' THEN AttrDef.AttrType := atEntity  
1838 - ELSE IF AttrDef.TypeDef = 'ENTITIES' THEN AttrDef.AttrType := atEntities  
1839 - ELSE IF AttrDef.TypeDef = 'NMTOKEN' THEN AttrDef.AttrType := atNmToken  
1840 - ELSE IF AttrDef.TypeDef = 'NMTOKENS' THEN AttrDef.AttrType := atNmTokens;  
1841 - Phase := phDefault;  
1842 - END  
1843 - END;  
1844 - phNotationContent : BEGIN  
1845 - F := StrScan (Final, ')');  
1846 - IF F <> NIL THEN  
1847 - SetStringSF (AttrDef.Notations, Final+1, F-1)  
1848 - ELSE BEGIN  
1849 - AttrDef.Notations := STRING (Final+1);  
1850 - Final := StrEnd (Final);  
1851 - END;  
1852 - ReplaceParameterEntities (AttrDef.Notations);  
1853 - AttrDef.Notations := DelChars (AttrDef.Notations, CWhitespace);  
1854 - Phase := phDefault;  
1855 - END;  
1856 - phDefault : BEGIN  
1857 - IF Final^ = '#' THEN BEGIN  
1858 - ExtractName (Final, CWhiteSpace + CQuoteChar, F);  
1859 - SetStringSF (Strg, Final, F);  
1860 - Final := F;  
1861 - ReplaceParameterEntities (Strg);  
1862 - IF Strg = '#REQUIRED' THEN BEGIN AttrDef.DefaultType := adRequired; Phase := phName; END  
1863 - ELSE IF Strg = '#IMPLIED' THEN BEGIN AttrDef.DefaultType := adImplied; Phase := phName; END  
1864 - ELSE IF Strg = '#FIXED' THEN AttrDef.DefaultType := adFixed;  
1865 - END  
1866 - ELSE IF (Final^ IN CQuoteChar) THEN BEGIN  
1867 - ExtractQuote (Final, AttrDef.Value, Final);  
1868 - ReplaceParameterEntities (AttrDef.Value);  
1869 - ReplaceCharacterEntities (AttrDef.Value);  
1870 - Phase := phName;  
1871 - END;  
1872 - IF Phase = phName THEN BEGIN  
1873 - AttrDef := NIL;  
1874 - END;  
1875 - END;  
1876 -  
1877 - END;  
1878 - END;  
1879 - INC (Final);  
1880 - UNTIL FALSE;  
1881 -  
1882 - Final := StrScan (Final, '>');  
1883 -  
1884 - DER.ElementType := deAttList;  
1885 - DER.ElemDef := ElemDef;  
1886 - DER.Final := Final;  
1887 - DtdElementFound (DER);  
1888 -END;  
1889 -  
1890 -  
1891 -PROCEDURE TXmlParser.AnalyzeEntityDecl (Start : PChar; VAR Final : PChar);  
1892 - (* Parse <!ENTITY declaration starting at "Start"  
1893 - Final must point to the terminating '>' character  
1894 - XmlSpec 4.2:  
1895 - EntityDecl ::= '<!ENTITY' S Name S EntityDef S? '>' |  
1896 - '<!ENTITY' S '%' S Name S PEDef S? '>'  
1897 - EntityDef ::= EntityValue | (ExternalID NDataDecl?)  
1898 - PEDef ::= EntityValue | ExternalID  
1899 - NDataDecl ::= S 'NDATA' S Name  
1900 - EntityValue ::= '"' ([^%&"] | PEReference | EntityRef | CharRef)* '"' |  
1901 - "'" ([^%&'] | PEReference | EntityRef | CharRef)* "'"  
1902 - PEReference ::= '%' Name ';'  
1903 -  
1904 - Examples  
1905 - <!ENTITY test1 "Stefan Heymann"> <!-- Internal, general, parsed -->  
1906 - <!ENTITY test2 SYSTEM "ent2.xml"> <!-- External, general, parsed -->  
1907 - <!ENTITY test2 SYSTEM "ent3.gif" NDATA gif> <!-- External, general, unparsed -->  
1908 - <!ENTITY % test3 "<!ELEMENT q ANY>"> <!-- Internal, parameter -->  
1909 - <!ENTITY % test6 SYSTEM "ent6.xml"> <!-- External, parameter -->  
1910 - <!ENTITY test4 "&test1; ist lieb"> <!-- IGP, Replacement text <> literal value -->  
1911 - <!ENTITY test5 "<p>Dies ist ein Test-Absatz</p>"> <!-- IGP, See XmlSpec 2.4 -->  
1912 - *)  
1913 -TYPE  
1914 - TPhase = (phName, phContent, phNData, phNotationName, phFinalGT);  
1915 -VAR  
1916 - Phase : TPhase;  
1917 - IsParamEntity : BOOLEAN;  
1918 - F : PChar;  
1919 - ExternalID : TExternalID;  
1920 - EntityDef : TEntityDef;  
1921 - EntityDef2 : TEntityDef;  
1922 - DER : TDtdElementRec;  
1923 -BEGIN  
1924 - Final := Start + 8; // First char after <!ENTITY  
1925 - DER.Start := Start;  
1926 - Phase := phName;  
1927 - IsParamEntity := FALSE;  
1928 - EntityDef := TEntityDef.Create;  
1929 - REPEAT  
1930 - IF NOT (Final^ IN CWhitespace) THEN  
1931 - CASE Final^ OF  
1932 - '%' : IsParamEntity := TRUE;  
1933 - '>' : BREAK;  
1934 - ELSE CASE Phase OF  
1935 - phName : IF Final^ IN CNameStart THEN BEGIN  
1936 - ExtractName (Final, CWhitespace + CQuoteChar, F);  
1937 - SetStringSF (EntityDef.Name, Final, F);  
1938 - Final := F;  
1939 - Phase := phContent;  
1940 - END;  
1941 - phContent : IF Final^ IN CQuoteChar THEN BEGIN  
1942 - ExtractQuote (Final, EntityDef.Value, Final);  
1943 - Phase := phFinalGT;  
1944 - END  
1945 - ELSE IF (StrLComp (Final, 'SYSTEM', 6) = 0) OR  
1946 - (StrLComp (Final, 'PUBLIC', 6) = 0) THEN BEGIN  
1947 - ExternalID := TExternalID.Create (Final);  
1948 - EntityDef.SystemId := ExternalID.SystemId;  
1949 - EntityDef.PublicId := ExternalID.PublicId;  
1950 - Final := ExternalID.Final;  
1951 - Phase := phNData;  
1952 - ExternalID.Free;  
1953 - END;  
1954 - phNData : IF StrLComp (Final, 'NDATA', 5) = 0 THEN BEGIN  
1955 - INC (Final, 4);  
1956 - Phase := phNotationName;  
1957 - END;  
1958 - phNotationName : IF Final^ IN CNameStart THEN BEGIN  
1959 - ExtractName (Final, CWhitespace + ['>'], F);  
1960 - SetStringSF (EntityDef.NotationName, Final, F);  
1961 - Final := F;  
1962 - Phase := phFinalGT;  
1963 - END;  
1964 - phFinalGT : ; // -!- There is an error in the document if this branch is called  
1965 - END;  
1966 - END;  
1967 - INC (Final);  
1968 - UNTIL FALSE;  
1969 - IF IsParamEntity THEN BEGIN  
1970 - EntityDef2 := TEntityDef (ParEntities.Node (EntityDef.Name));  
1971 - IF EntityDef2 <> NIL THEN  
1972 - ParEntities.Delete (ParEntities.IndexOf (EntityDef2));  
1973 - ParEntities.Add (EntityDef);  
1974 - ReplaceCharacterEntities (EntityDef.Value);  
1975 - END  
1976 - ELSE BEGIN  
1977 - EntityDef2 := TEntityDef (Entities.Node (EntityDef.Name));  
1978 - IF EntityDef2 <> NIL THEN  
1979 - Entities.Delete (Entities.IndexOf (EntityDef2));  
1980 - Entities.Add (EntityDef);  
1981 - ReplaceParameterEntities (EntityDef.Value); // Create replacement texts (see XmlSpec 4.5)  
1982 - ReplaceCharacterEntities (EntityDef.Value);  
1983 - END;  
1984 - Final := StrScanE (Final, '>');  
1985 -  
1986 - DER.ElementType := deEntity;  
1987 - DER.EntityDef := EntityDef;  
1988 - DER.Final := Final;  
1989 - DtdElementFound (DER);  
1990 -END;  
1991 -  
1992 -  
1993 -PROCEDURE TXmlParser.AnalyzeNotationDecl (Start : PChar; VAR Final : PChar);  
1994 - // Parse <!NOTATION declaration starting at "Start"  
1995 - // Final must point to the terminating '>' character  
1996 - // XmlSpec 4.7: NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'  
1997 -TYPE  
1998 - TPhase = (phName, phExtId, phEnd);  
1999 -VAR  
2000 - ExternalID : TExternalID;  
2001 - Phase : TPhase;  
2002 - F : PChar;  
2003 - NotationDef : TNotationDef;  
2004 - DER : TDtdElementRec;  
2005 -BEGIN  
2006 - Final := Start + 10; // Character after <!NOTATION  
2007 - DER.Start := Start;  
2008 - Phase := phName;  
2009 - NotationDef := TNotationDef.Create;  
2010 - REPEAT  
2011 - IF NOT (Final^ IN CWhitespace) THEN  
2012 - CASE Final^ OF  
2013 - '>',  
2014 - #0 : BREAK;  
2015 - ELSE CASE Phase OF  
2016 - phName : BEGIN  
2017 - ExtractName (Final, CWhitespace + ['>'], F);  
2018 - SetStringSF (NotationDef.Name, Final, F);  
2019 - Final := F;  
2020 - Phase := phExtId;  
2021 - END;  
2022 - phExtId : BEGIN  
2023 - ExternalID := TExternalID.Create (Final);  
2024 - NotationDef.Value := ExternalID.SystemId;  
2025 - NotationDef.PublicId := ExternalID.PublicId;  
2026 - Final := ExternalId.Final;  
2027 - ExternalId.Free;  
2028 - Phase := phEnd;  
2029 - END;  
2030 - phEnd : ; // -!- There is an error in the document if this branch is called  
2031 - END;  
2032 - END;  
2033 - INC (Final);  
2034 - UNTIL FALSE;  
2035 - Notations.Add (NotationDef);  
2036 - Final := StrScanE (Final, '>');  
2037 -  
2038 - DER.ElementType := deNotation;  
2039 - DER.NotationDef := NotationDef;  
2040 - DER.Final := Final;  
2041 - DtdElementFound (DER);  
2042 -END;  
2043 -  
2044 -  
2045 -PROCEDURE TXmlParser.PushPE (VAR Start : PChar);  
2046 - (* If there is a parameter entity reference found in the data stream,  
2047 - the current position will be pushed to the entity stack.  
2048 - Start: IN Pointer to the '%' character starting the PE reference  
2049 - OUT Pointer to first character of PE replacement text *)  
2050 -VAR  
2051 - P : PChar;  
2052 - EntityDef : TEntityDef;  
2053 -BEGIN  
2054 - P := StrScan (Start, ';');  
2055 - IF P <> NIL THEN BEGIN  
2056 - EntityDef := TEntityDef (ParEntities.Node (StrSFPas (Start+1, P-1)));  
2057 - IF EntityDef <> NIL THEN BEGIN  
2058 - EntityStack.Push (P+1);  
2059 - Start := PChar (EntityDef.Value);  
2060 - END  
2061 - ELSE  
2062 - Start := P+1;  
2063 - END;  
2064 -END;  
2065 -  
2066 -  
2067 -PROCEDURE TXmlParser.ReplaceCharacterEntities (VAR Str : STRING);  
2068 - // Replaces all Character Entity References in the String  
2069 -VAR  
2070 - Start : INTEGER;  
2071 - PAmp : PChar;  
2072 - PSemi : PChar;  
2073 - PosAmp : INTEGER;  
2074 - Len : INTEGER; // Length of Entity Reference  
2075 -BEGIN  
2076 - IF Str = '' THEN EXIT;  
2077 - Start := 1;  
2078 - REPEAT  
2079 - PAmp := StrPos (PChar (Str) + Start-1, '&#');  
2080 - IF PAmp = NIL THEN BREAK;  
2081 - PSemi := StrScan (PAmp+2, ';');  
2082 - IF PSemi = NIL THEN BREAK;  
2083 - PosAmp := PAmp - PChar (Str) + 1;  
2084 - Len := PSemi-PAmp+1;  
2085 - IF CompareText (Str [PosAmp+2], 'x') = 0 // !!! Can't use "CHR" for Unicode characters > 255  
2086 - THEN Str [PosAmp] := CHR (StrToIntDef ('$'+Copy (Str, PosAmp+3, Len-4), 0))  
2087 - ELSE Str [PosAmp] := CHR (StrToIntDef (Copy (Str, PosAmp+2, Len-3), 32));  
2088 - Delete (Str, PosAmp+1, Len-1);  
2089 - Start := PosAmp + 1;  
2090 - UNTIL FALSE;  
2091 -END;  
2092 -  
2093 -  
2094 -PROCEDURE TXmlParser.ReplaceParameterEntities (VAR Str : STRING);  
2095 - // Recursively replaces all Parameter Entity References in the String  
2096 - PROCEDURE ReplaceEntities (VAR Str : STRING);  
2097 - VAR  
2098 - Start : INTEGER;  
2099 - PAmp : PChar;  
2100 - PSemi : PChar;  
2101 - PosAmp : INTEGER;  
2102 - Len : INTEGER;  
2103 - Entity : TEntityDef;  
2104 - Repl : STRING; // Replacement  
2105 - BEGIN  
2106 - IF Str = '' THEN EXIT;  
2107 - Start := 1;  
2108 - REPEAT  
2109 - PAmp := StrPos (PChar (Str)+Start-1, '%');  
2110 - IF PAmp = NIL THEN BREAK;  
2111 - PSemi := StrScan (PAmp+2, ';');  
2112 - IF PSemi = NIL THEN BREAK;  
2113 - PosAmp := PAmp - PChar (Str) + 1;  
2114 - Len := PSemi-PAmp+1;  
2115 - Entity := TEntityDef (ParEntities.Node (Copy (Str, PosAmp+1, Len-2)));  
2116 - IF Entity <> NIL THEN BEGIN  
2117 - Repl := Entity.Value;  
2118 - ReplaceEntities (Repl); // Recursion  
2119 - END  
2120 - ELSE  
2121 - Repl := Copy (Str, PosAmp, Len);  
2122 - Delete (Str, PosAmp, Len);  
2123 - Insert (Repl, Str, PosAmp);  
2124 - Start := PosAmp + Length (Repl);  
2125 - UNTIL FALSE;  
2126 - END;  
2127 -BEGIN  
2128 - ReplaceEntities (Str);  
2129 -END;  
2130 -  
2131 -  
2132 -PROCEDURE TXmlParser.ReplaceGeneralEntities (VAR Str : STRING);  
2133 - // Recursively replaces General Entity References in the String  
2134 - PROCEDURE ReplaceEntities (VAR Str : STRING);  
2135 - VAR  
2136 - Start : INTEGER;  
2137 - PAmp : PChar;  
2138 - PSemi : PChar;  
2139 - PosAmp : INTEGER;  
2140 - Len : INTEGER;  
2141 - EntityDef : TEntityDef;  
2142 - EntName : STRING;  
2143 - Repl : STRING; // Replacement  
2144 - ExternalEntity : TXmlParser;  
2145 - BEGIN  
2146 - IF Str = '' THEN EXIT;  
2147 - Start := 1;  
2148 - REPEAT  
2149 - PAmp := StrPos (PChar (Str)+Start-1, '&');  
2150 - IF PAmp = NIL THEN BREAK;  
2151 - PSemi := StrScan (PAmp+2, ';');  
2152 - IF PSemi = NIL THEN BREAK;  
2153 - PosAmp := PAmp - PChar (Str) + 1;  
2154 - Len := PSemi-PAmp+1;  
2155 - EntName := Copy (Str, PosAmp+1, Len-2);  
2156 - IF EntName = 'lt' THEN Repl := '<'  
2157 - ELSE IF EntName = 'gt' THEN Repl := '>'  
2158 - ELSE IF EntName = 'amp' THEN Repl := '&'  
2159 - ELSE IF EntName = 'apos' THEN Repl := ''''  
2160 - ELSE IF EntName = 'quot' THEN Repl := '"'  
2161 - ELSE BEGIN  
2162 - EntityDef := TEntityDef (Entities.Node (EntName));  
2163 - IF EntityDef <> NIL THEN BEGIN  
2164 - IF EntityDef.Value <> '' THEN // Internal Entity  
2165 - Repl := EntityDef.Value  
2166 - ELSE BEGIN // External Entity  
2167 - ExternalEntity := LoadExternalEntity (EntityDef.SystemId, EntityDef.PublicId, EntityDef.NotationName);  
2168 - Repl := StrPas (ExternalEntity.DocBuffer); // !!! What if it contains a Text Declaration?  
2169 - ExternalEntity.Free;  
2170 - END;  
2171 - ReplaceEntities (Repl); // Recursion  
2172 - END  
2173 - ELSE  
2174 - Repl := Copy (Str, PosAmp, Len);  
2175 - END;  
2176 - Delete (Str, PosAmp, Len);  
2177 - Insert (Repl, Str, PosAmp);  
2178 - Start := PosAmp + Length (Repl);  
2179 - UNTIL FALSE;  
2180 - END;  
2181 -BEGIN  
2182 - ReplaceEntities (Str);  
2183 -END;  
2184 -  
2185 -  
2186 -FUNCTION TXmlParser.LoadExternalEntity (SystemId, PublicId, Notation : STRING) : TXmlParser;  
2187 - // This will be called whenever there is a Parsed External Entity or  
2188 - // the DTD External Subset to be parsed.  
2189 - // It has to create a TXmlParser instance and load the desired Entity.  
2190 - // This instance of LoadExternalEntity assumes that "SystemId" is a valid  
2191 - // file name (relative to the Document source) and loads this file using  
2192 - // the LoadFromFile method.  
2193 -VAR  
2194 - Filename : STRING;  
2195 -BEGIN  
2196 - // --- Convert System ID to complete filename  
2197 - Filename := StringReplace (SystemId, '/', '\', [rfReplaceAll]);  
2198 - IF Copy (FSource, 1, 1) <> '<' THEN  
2199 - IF (Copy (Filename, 1, 2) = '\\') OR (Copy (Filename, 2, 1) = ':') THEN  
2200 - // Already has an absolute Path  
2201 - ELSE BEGIN  
2202 - Filename := ExtractFilePath (FSource) + Filename;  
2203 - END;  
2204 -  
2205 - // --- Load the File  
2206 - Result := TXmlParser.Create;  
2207 - Result.LoadFromFile (Filename);  
2208 -END;  
2209 -  
2210 -  
2211 -FUNCTION TXmlParser.TranslateEncoding (CONST Source : STRING) : STRING;  
2212 - // The member variable "CurEncoding" always holds the name of the current  
2213 - // encoding, e.g. 'UTF-8' or 'ISO-8859-1'.  
2214 - // This virtual method "TranslateEncoding" is responsible for translating  
2215 - // the content passed in the "Source" parameter to the Encoding which  
2216 - // is expected by the application.  
2217 - // This instance of "TranlateEncoding" assumes that the Application expects  
2218 - // Windows ANSI (Win1252) strings. It is able to transform UTF-8 or ISO-8859-1  
2219 - // encodings.  
2220 - // If you want your application to understand or create other encodings, you  
2221 - // override this function.  
2222 -BEGIN  
2223 - IF CurEncoding = 'UTF-8'  
2224 - THEN Result := Utf8ToAnsi (Source)  
2225 - ELSE Result := Source;  
2226 -END;  
2227 -  
2228 -  
2229 -PROCEDURE TXmlParser.DtdElementFound (DtdElementRec : TDtdElementRec);  
2230 - // This method is called for every element which is found in the DTD  
2231 - // declaration. The variant record TDtdElementRec is passed which  
2232 - // holds informations about the element.  
2233 - // You can override this function to handle DTD declarations.  
2234 - // Note that when you parse the same Document instance a second time,  
2235 - // the DTD will not get parsed again.  
2236 -BEGIN  
2237 -END;  
2238 -  
2239 -  
2240 -FUNCTION TXmlParser.GetDocBuffer: PChar;  
2241 - // Returns FBuffer or a pointer to a NUL char if Buffer is empty  
2242 -BEGIN  
2243 - IF FBuffer = NIL  
2244 - THEN Result := #0  
2245 - ELSE Result := FBuffer;  
2246 -END;  
2247 -  
2248 -  
2249 -(*$IFNDEF HAS_CONTNRS_UNIT  
2250 -===============================================================================================  
2251 -TObjectList  
2252 -===============================================================================================  
2253 -*)  
2254 -  
2255 -DESTRUCTOR TObjectList.Destroy;  
2256 -BEGIN  
2257 - Clear;  
2258 - SetCapacity(0);  
2259 - INHERITED Destroy;  
2260 -END;  
2261 -  
2262 -  
2263 -PROCEDURE TObjectList.Delete (Index : INTEGER);  
2264 -BEGIN  
2265 - IF (Index < 0) OR (Index >= Count) THEN EXIT;  
2266 - TObject (Items [Index]).Free;  
2267 - INHERITED Delete (Index);  
2268 -END;  
2269 -  
2270 -  
2271 -PROCEDURE TObjectList.Clear;  
2272 -BEGIN  
2273 - WHILE Count > 0 DO  
2274 - Delete (Count-1);  
2275 -END;  
2276 -  
2277 -(*$ENDIF *)  
2278 -  
2279 -(*  
2280 -===============================================================================================  
2281 -TNvpNode  
2282 ---------  
2283 -Node base class for the TNvpList  
2284 -===============================================================================================  
2285 -*)  
2286 -  
2287 -CONSTRUCTOR TNvpNode.Create (TheName, TheValue : STRING);  
2288 -BEGIN  
2289 - INHERITED Create;  
2290 - Name := TheName;  
2291 - Value := TheValue;  
2292 -END;  
2293 -  
2294 -  
2295 -(*  
2296 -===============================================================================================  
2297 -TNvpList  
2298 ---------  
2299 -A generic List of Name-Value Pairs, based on the TObjectList introduced in Delphi 5  
2300 -===============================================================================================  
2301 -*)  
2302 -  
2303 -PROCEDURE TNvpList.Add (Node : TNvpNode);  
2304 -VAR  
2305 - I : INTEGER;  
2306 -BEGIN  
2307 - FOR I := Count-1 DOWNTO 0 DO  
2308 - IF Node.Name > TNvpNode (Items [I]).Name THEN BEGIN  
2309 - Insert (I+1, Node);  
2310 - EXIT;  
2311 - END;  
2312 - Insert (0, Node);  
2313 -END;  
2314 -  
2315 -  
2316 -  
2317 -FUNCTION TNvpList.Node (Name : STRING) : TNvpNode;  
2318 - // Binary search for Node  
2319 -VAR  
2320 - L, H : INTEGER; // Low, High Limit  
2321 - T, C : INTEGER; // Test Index, Comparison result  
2322 - Last : INTEGER; // Last Test Index  
2323 -BEGIN  
2324 - IF Count=0 THEN BEGIN  
2325 - Result := NIL;  
2326 - EXIT;  
2327 - END;  
2328 -  
2329 - L := 0;  
2330 - H := Count;  
2331 - Last := -1;  
2332 - REPEAT  
2333 - T := (L+H) DIV 2;  
2334 - IF T=Last THEN BREAK;  
2335 - Result := TNvpNode (Items [T]);  
2336 - C := CompareStr (Result.Name, Name);  
2337 - IF C = 0 THEN EXIT  
2338 - ELSE IF C < 0 THEN L := T  
2339 - ELSE H := T;  
2340 - Last := T;  
2341 - UNTIL FALSE;  
2342 - Result := NIL;  
2343 -END;  
2344 -  
2345 -  
2346 -FUNCTION TNvpList.Node (Index : INTEGER) : TNvpNode;  
2347 -BEGIN  
2348 - IF (Index < 0) OR (Index >= Count)  
2349 - THEN Result := NIL  
2350 - ELSE Result := TNvpNode (Items [Index]);  
2351 -END;  
2352 -  
2353 -  
2354 -FUNCTION TNvpList.Value (Name : STRING) : STRING;  
2355 -VAR  
2356 - Nvp : TNvpNode;  
2357 -BEGIN  
2358 - Nvp := TNvpNode (Node (Name));  
2359 - IF Nvp <> NIL  
2360 - THEN Result := Nvp.Value  
2361 - ELSE Result := '';  
2362 -END;  
2363 -  
2364 -  
2365 -FUNCTION TNvpList.Value (Index : INTEGER) : STRING;  
2366 -BEGIN  
2367 - IF (Index < 0) OR (Index >= Count)  
2368 - THEN Result := ''  
2369 - ELSE Result := TNvpNode (Items [Index]).Value;  
2370 -END;  
2371 -  
2372 -  
2373 -FUNCTION TNvpList.Name (Index : INTEGER) : STRING;  
2374 -BEGIN  
2375 - IF (Index < 0) OR (Index >= Count)  
2376 - THEN Result := ''  
2377 - ELSE Result := TNvpNode (Items [Index]).Name;  
2378 -END;  
2379 -  
2380 -  
2381 -(*  
2382 -===============================================================================================  
2383 -TAttrList  
2384 -List of Attributes. The "Analyze" method extracts the Attributes from the given Buffer.  
2385 -Is used for extraction of Attributes in Start-Tags, Empty-Element Tags and the "pseudo"  
2386 -attributes in XML Prologs, Text Declarations and PIs.  
2387 -===============================================================================================  
2388 -*)  
2389 -  
2390 -PROCEDURE TAttrList.Analyze (Start : PChar; VAR Final : PChar);  
2391 - // Analyze the Buffer for Attribute=Name pairs.  
2392 - // Terminates when there is a character which is not IN CNameStart  
2393 - // (e.g. '?>' or '>' or '/>')  
2394 -TYPE  
2395 - TPhase = (phName, phEq, phValue);  
2396 -VAR  
2397 - Phase : TPhase;  
2398 - F : PChar;  
2399 - Name : STRING;  
2400 - Value : STRING;  
2401 - Attr : TAttr;  
2402 -BEGIN  
2403 - Clear;  
2404 - Phase := phName;  
2405 - Final := Start;  
2406 - REPEAT  
2407 - IF (Final^ = #0) OR (Final^ = '>') THEN BREAK;  
2408 - IF NOT (Final^ IN CWhitespace) THEN  
2409 - CASE Phase OF  
2410 - phName : BEGIN  
2411 - IF NOT (Final^ IN CNameStart) THEN EXIT;  
2412 - ExtractName (Final, CWhitespace + ['=', '/'], F);  
2413 - SetStringSF (Name, Final, F);  
2414 - Final := F;  
2415 - Phase := phEq;  
2416 - END;  
2417 - phEq : BEGIN  
2418 - IF Final^ = '=' THEN  
2419 - Phase := phValue  
2420 - END;  
2421 - phValue : BEGIN  
2422 - IF Final^ IN CQuoteChar THEN BEGIN  
2423 - ExtractQuote (Final, Value, F);  
2424 - Attr := TAttr.Create;  
2425 - Attr.Name := Name;  
2426 - Attr.Value := Value;  
2427 - Attr.ValueType := vtNormal;  
2428 - Add (Attr);  
2429 - Final := F;  
2430 - Phase := phName;  
2431 - END;  
2432 - END;  
2433 - END;  
2434 - INC (Final);  
2435 - UNTIL FALSE;  
2436 -END;  
2437 -  
2438 -  
2439 -(*  
2440 -===============================================================================================  
2441 -TElemList  
2442 -List of TElemDef nodes.  
2443 -===============================================================================================  
2444 -*)  
2445 -  
2446 -FUNCTION TElemList.Node (Name : STRING) : TElemDef;  
2447 - // Binary search for the Node with the given Name  
2448 -VAR  
2449 - L, H : INTEGER; // Low, High Limit  
2450 - T, C : INTEGER; // Test Index, Comparison result  
2451 - Last : INTEGER; // Last Test Index  
2452 -BEGIN  
2453 - IF Count=0 THEN BEGIN  
2454 - Result := NIL;  
2455 - EXIT;  
2456 - END;  
2457 -  
2458 - L := 0;  
2459 - H := Count;  
2460 - Last := -1;  
2461 - REPEAT  
2462 - T := (L+H) DIV 2;  
2463 - IF T=Last THEN BREAK;  
2464 - Result := TElemDef (Items [T]);  
2465 - C := CompareStr (Result.Name, Name);  
2466 - IF C = 0 THEN EXIT  
2467 - ELSE IF C < 0 THEN L := T  
2468 - ELSE H := T;  
2469 - Last := T;  
2470 - UNTIL FALSE;  
2471 - Result := NIL;  
2472 -END;  
2473 -  
2474 -  
2475 -PROCEDURE TElemList.Add (Node : TElemDef);  
2476 -VAR  
2477 - I : INTEGER;  
2478 -BEGIN  
2479 - FOR I := Count-1 DOWNTO 0 DO  
2480 - IF Node.Name > TElemDef (Items [I]).Name THEN BEGIN  
2481 - Insert (I+1, Node);  
2482 - EXIT;  
2483 - END;  
2484 - Insert (0, Node);  
2485 -END;  
2486 -  
2487 -  
2488 -(*  
2489 -===============================================================================================  
2490 -TScannerXmlParser  
2491 -A TXmlParser descendant for the TCustomXmlScanner component  
2492 -===============================================================================================  
2493 -*)  
2494 -  
2495 -TYPE  
2496 - TScannerXmlParser = CLASS (TXmlParser)  
2497 - Scanner : TCustomXmlScanner;  
2498 - CONSTRUCTOR Create (TheScanner : TCustomXmlScanner);  
2499 - FUNCTION LoadExternalEntity (SystemId, PublicId,  
2500 - Notation : STRING) : TXmlParser; OVERRIDE;  
2501 - FUNCTION TranslateEncoding (CONST Source : STRING) : STRING; OVERRIDE;  
2502 - PROCEDURE DtdElementFound (DtdElementRec : TDtdElementRec); OVERRIDE;  
2503 - END;  
2504 -  
2505 -CONSTRUCTOR TScannerXmlParser.Create (TheScanner : TCustomXmlScanner);  
2506 -BEGIN  
2507 - INHERITED Create;  
2508 - Scanner := TheScanner;  
2509 -END;  
2510 -  
2511 -  
2512 -FUNCTION TScannerXmlParser.LoadExternalEntity (SystemId, PublicId, Notation : STRING) : TXmlParser;  
2513 -BEGIN  
2514 - IF Assigned (Scanner.FOnLoadExternal)  
2515 - THEN Scanner.FOnLoadExternal (Scanner, SystemId, PublicId, Notation, Result)  
2516 - ELSE Result := INHERITED LoadExternalEntity (SystemId, PublicId, Notation);  
2517 -END;  
2518 -  
2519 -  
2520 -FUNCTION TScannerXmlParser.TranslateEncoding (CONST Source : STRING) : STRING;  
2521 -BEGIN  
2522 - IF Assigned (Scanner.FOnTranslateEncoding)  
2523 - THEN Result := Scanner.FOnTranslateEncoding (Scanner, CurEncoding, Source)  
2524 - ELSE Result := INHERITED TranslateEncoding (Source);  
2525 -END;  
2526 -  
2527 -  
2528 -PROCEDURE TScannerXmlParser.DtdElementFound (DtdElementRec : TDtdElementRec);  
2529 -BEGIN  
2530 - WITH DtdElementRec DO  
2531 - CASE ElementType OF  
2532 - deElement : Scanner.WhenElement (ElemDef);  
2533 - deAttList : Scanner.WhenAttList (ElemDef);  
2534 - deEntity : Scanner.WhenEntity (EntityDef);  
2535 - deNotation : Scanner.WhenNotation (NotationDef);  
2536 - dePI : Scanner.WhenPI (STRING (Target), STRING (Content), AttrList);  
2537 - deComment : Scanner.WhenComment (StrSFPas (Start, Final));  
2538 - deError : Scanner.WhenDtdError (Pos);  
2539 - END;  
2540 -END;  
2541 -  
2542 -  
2543 -(*  
2544 -===============================================================================================  
2545 -TCustomXmlScanner  
2546 -===============================================================================================  
2547 -*)  
2548 -  
2549 -CONSTRUCTOR TCustomXmlScanner.Create (AOwner: TComponent);  
2550 -BEGIN  
2551 - INHERITED;  
2552 - FXmlParser := TScannerXmlParser.Create (Self);  
2553 -END;  
2554 -  
2555 -  
2556 -DESTRUCTOR TCustomXmlScanner.Destroy;  
2557 -BEGIN  
2558 - FXmlParser.Free;  
2559 - INHERITED;  
2560 -END;  
2561 -  
2562 -  
2563 -PROCEDURE TCustomXmlScanner.LoadFromFile (Filename : TFilename);  
2564 - // Load XML Document from file  
2565 -BEGIN  
2566 - FXmlParser.LoadFromFile (Filename);  
2567 -END;  
2568 -  
2569 -  
2570 -PROCEDURE TCustomXmlScanner.LoadFromBuffer (Buffer : PChar);  
2571 - // Load XML Document from buffer  
2572 -BEGIN  
2573 - FXmlParser.LoadFromBuffer (Buffer);  
2574 -END;  
2575 -  
2576 -  
2577 -PROCEDURE TCustomXmlScanner.SetBuffer (Buffer : PChar);  
2578 - // Refer to Buffer  
2579 -BEGIN  
2580 - FXmlParser.SetBuffer (Buffer);  
2581 -END;  
2582 -  
2583 -  
2584 -FUNCTION TCustomXmlScanner.GetFilename : TFilename;  
2585 -BEGIN  
2586 - Result := FXmlParser.Source;  
2587 -END;  
2588 -  
2589 -  
2590 -FUNCTION TCustomXmlScanner.GetNormalize : BOOLEAN;  
2591 -BEGIN  
2592 - Result := FXmlParser.Normalize;  
2593 -END;  
2594 -  
2595 -  
2596 -PROCEDURE TCustomXmlScanner.SetNormalize (Value : BOOLEAN);  
2597 -BEGIN  
2598 - FXmlParser.Normalize := Value;  
2599 -END;  
2600 -  
2601 -  
2602 -PROCEDURE TCustomXmlScanner.WhenXmlProlog(XmlVersion, Encoding: STRING; Standalone : BOOLEAN);  
2603 - // Is called when the parser has parsed the <? xml ?> declaration of the prolog  
2604 -BEGIN  
2605 - IF Assigned (FOnXmlProlog) THEN FOnXmlProlog (Self, XmlVersion, Encoding, Standalone);  
2606 -END;  
2607 -  
2608 -  
2609 -PROCEDURE TCustomXmlScanner.WhenComment (Comment : STRING);  
2610 - // Is called when the parser has parsed a <!-- comment -->  
2611 -BEGIN  
2612 - IF Assigned (FOnComment) THEN FOnComment (Self, Comment);  
2613 -END;  
2614 -  
2615 -  
2616 -PROCEDURE TCustomXmlScanner.WhenPI (Target, Content: STRING; Attributes : TAttrList);  
2617 - // Is called when the parser has parsed a <?processing instruction ?>  
2618 -BEGIN  
2619 - IF Assigned (FOnPI) THEN FOnPI (Self, Target, Content, Attributes);  
2620 -END;  
2621 -  
2622 -  
2623 -PROCEDURE TCustomXmlScanner.WhenDtdRead (RootElementName : STRING);  
2624 - // Is called when the parser has completely parsed the DTD  
2625 -BEGIN  
2626 - IF Assigned (FOnDtdRead) THEN FOnDtdRead (Self, RootElementName);  
2627 -END;  
2628 -  
2629 -  
2630 -PROCEDURE TCustomXmlScanner.WhenStartTag (TagName : STRING; Attributes : TAttrList);  
2631 - // Is called when the parser has parsed a start tag like <p>  
2632 -BEGIN  
2633 - IF Assigned (FOnStartTag) THEN FOnStartTag (Self, TagName, Attributes);  
2634 -END;  
2635 -  
2636 -  
2637 -PROCEDURE TCustomXmlScanner.WhenEmptyTag (TagName : STRING; Attributes : TAttrList);  
2638 - // Is called when the parser has parsed an Empty Element Tag like <br/>  
2639 -BEGIN  
2640 - IF Assigned (FOnEmptyTag) THEN FOnEmptyTag (Self, TagName, Attributes);  
2641 -END;  
2642 -  
2643 -  
2644 -PROCEDURE TCustomXmlScanner.WhenEndTag (TagName : STRING);  
2645 - // Is called when the parser has parsed an End Tag like </p>  
2646 -BEGIN  
2647 - IF Assigned (FOnEndTag) THEN FOnEndTag (Self, TagName);  
2648 -END;  
2649 -  
2650 -  
2651 -PROCEDURE TCustomXmlScanner.WhenContent (Content : STRING);  
2652 - // Is called when the parser has parsed an element's text content  
2653 -BEGIN  
2654 - IF Assigned (FOnContent) THEN FOnContent (Self, Content);  
2655 -END;  
2656 -  
2657 -  
2658 -PROCEDURE TCustomXmlScanner.WhenCData (Content : STRING);  
2659 - // Is called when the parser has parsed a CDATA section  
2660 -BEGIN  
2661 - IF Assigned (FOnCData) THEN FOnCData (Self, Content);  
2662 -END;  
2663 -  
2664 -  
2665 -PROCEDURE TCustomXmlScanner.WhenElement (ElemDef : TElemDef);  
2666 - // Is called when the parser has parsed an <!ELEMENT> definition  
2667 - // inside the DTD  
2668 -BEGIN  
2669 - IF Assigned (FOnElement) THEN FOnElement (Self, ElemDef);  
2670 -END;  
2671 -  
2672 -  
2673 -PROCEDURE TCustomXmlScanner.WhenAttList (ElemDef : TElemDef);  
2674 - // Is called when the parser has parsed an <!ATTLIST> definition  
2675 - // inside the DTD  
2676 -BEGIN  
2677 - IF Assigned (FOnAttList) THEN FOnAttList (Self, ElemDef);  
2678 -END;  
2679 -  
2680 -  
2681 -PROCEDURE TCustomXmlScanner.WhenEntity (EntityDef : TEntityDef);  
2682 - // Is called when the parser has parsed an <!ENTITY> definition  
2683 - // inside the DTD  
2684 -BEGIN  
2685 - IF Assigned (FOnEntity) THEN FOnEntity (Self, EntityDef);  
2686 -END;  
2687 -  
2688 -  
2689 -PROCEDURE TCustomXmlScanner.WhenNotation (NotationDef : TNotationDef);  
2690 - // Is called when the parser has parsed a <!NOTATION> definition  
2691 - // inside the DTD  
2692 -BEGIN  
2693 - IF Assigned (FOnNotation) THEN FOnNotation (Self, NotationDef);  
2694 -END;  
2695 -  
2696 -  
2697 -PROCEDURE TCustomXmlScanner.WhenDtdError (ErrorPos : PChar);  
2698 - // Is called when the parser has found an Error in the DTD  
2699 -BEGIN  
2700 - IF Assigned (FOnDtdError) THEN FOnDtdError (Self, ErrorPos);  
2701 -END;  
2702 -  
2703 -  
2704 -PROCEDURE TCustomXmlScanner.Execute;  
2705 - // Perform scanning  
2706 - // Scanning is done synchronously, i.e. you can expect events to be triggered  
2707 - // in the order of the XML data stream. Execute will finish when the whole XML  
2708 - // document has been scanned or when the StopParser property has been set to TRUE.  
2709 -BEGIN  
2710 - FStopParser := FALSE;  
2711 - FXmlParser.StartScan;  
2712 - WHILE FXmlParser.Scan AND (NOT FStopParser) DO  
2713 - CASE FXmlParser.CurPartType OF  
2714 - ptNone : ;  
2715 - ptXmlProlog : WhenXmlProlog (FXmlParser.XmlVersion, FXmlParser.Encoding, FXmlParser.Standalone);  
2716 - ptComment : WhenComment (StrSFPas (FXmlParser.CurStart, FXmlParser.CurFinal));  
2717 - ptPI : WhenPI (FXmlParser.CurName, FXmlParser.CurContent, FXmlParser.CurAttr);  
2718 - ptDtdc : WhenDtdRead (FXmlParser.RootName);  
2719 - ptStartTag : WhenStartTag (FXmlParser.CurName, FXmlParser.CurAttr);  
2720 - ptEmptyTag : WhenEmptyTag (FXmlParser.CurName, FXmlParser.CurAttr);  
2721 - ptEndTag : WhenEndTag (FXmlParser.CurName);  
2722 - ptContent : WhenContent (FXmlParser.CurContent);  
2723 - ptCData : WhenCData (FXmlParser.CurContent);  
2724 - END;  
2725 -END;  
2726 -  
2727 -  
2728 -END.  
col_patr/col_patr.cfg
@@ -1,38 +0,0 @@ @@ -1,38 +0,0 @@
1 --$A8  
2 --$B-  
3 --$C+  
4 --$D+  
5 --$E-  
6 --$F-  
7 --$G+  
8 --$H+  
9 --$I+  
10 --$J-  
11 --$K-  
12 --$L+  
13 --$M-  
14 --$N+  
15 --$O+  
16 --$P+  
17 --$Q-  
18 --$R-  
19 --$S-  
20 --$T-  
21 --$U-  
22 --$V+  
23 --$W-  
24 --$X+  
25 --$YD  
26 --$Z1  
27 --cg  
28 --AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;  
29 --H+  
30 --W+  
31 --M  
32 --$M16384,1048576  
33 --K$00400000  
34 --LE"c:\arquivos de programas\borland\delphi7\Projects\Bpl"  
35 --LN"c:\arquivos de programas\borland\delphi7\Projects\Bpl"  
36 --w-UNSAFE_TYPE  
37 --w-UNSAFE_CODE  
38 --w-UNSAFE_CAST  
col_patr/col_patr.dof
@@ -1,136 +0,0 @@ @@ -1,136 +0,0 @@
1 -[FileVersion]  
2 -Version=7.0  
3 -[Compiler]  
4 -A=8  
5 -B=0  
6 -C=1  
7 -D=1  
8 -E=0  
9 -F=0  
10 -G=1  
11 -H=1  
12 -I=1  
13 -J=0  
14 -K=0  
15 -L=1  
16 -M=0  
17 -N=1  
18 -O=1  
19 -P=1  
20 -Q=0  
21 -R=0  
22 -S=0  
23 -T=0  
24 -U=0  
25 -V=1  
26 -W=0  
27 -X=1  
28 -Y=1  
29 -Z=1  
30 -ShowHints=1  
31 -ShowWarnings=1  
32 -UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;  
33 -NamespacePrefix=  
34 -SymbolDeprecated=1  
35 -SymbolLibrary=1  
36 -SymbolPlatform=1  
37 -UnitLibrary=1  
38 -UnitPlatform=1  
39 -UnitDeprecated=1  
40 -HResultCompat=1  
41 -HidingMember=1  
42 -HiddenVirtual=1  
43 -Garbage=1  
44 -BoundsError=1  
45 -ZeroNilCompat=1  
46 -StringConstTruncated=1  
47 -ForLoopVarVarPar=1  
48 -TypedConstVarPar=1  
49 -AsgToTypedConst=1  
50 -CaseLabelRange=1  
51 -ForVariable=1  
52 -ConstructingAbstract=1  
53 -ComparisonFalse=1  
54 -ComparisonTrue=1  
55 -ComparingSignedUnsigned=1  
56 -CombiningSignedUnsigned=1  
57 -UnsupportedConstruct=1  
58 -FileOpen=1  
59 -FileOpenUnitSrc=1  
60 -BadGlobalSymbol=1  
61 -DuplicateConstructorDestructor=1  
62 -InvalidDirective=1  
63 -PackageNoLink=1  
64 -PackageThreadVar=1  
65 -ImplicitImport=1  
66 -HPPEMITIgnored=1  
67 -NoRetVal=1  
68 -UseBeforeDef=1  
69 -ForLoopVarUndef=1  
70 -UnitNameMismatch=1  
71 -NoCFGFileFound=1  
72 -MessageDirective=1  
73 -ImplicitVariants=1  
74 -UnicodeToLocale=1  
75 -LocaleToUnicode=1  
76 -ImagebaseMultiple=1  
77 -SuspiciousTypecast=1  
78 -PrivatePropAccessor=1  
79 -UnsafeType=0  
80 -UnsafeCode=0  
81 -UnsafeCast=0  
82 -[Linker]  
83 -MapFile=0  
84 -OutputObjs=0  
85 -ConsoleApp=1  
86 -DebugInfo=0  
87 -RemoteSymbols=0  
88 -MinStackSize=16384  
89 -MaxStackSize=1048576  
90 -ImageBase=4194304  
91 -ExeDescription=  
92 -[Directories]  
93 -OutputDir=  
94 -UnitOutputDir=  
95 -PackageDLLOutputDir=  
96 -PackageDCPOutputDir=  
97 -SearchPath=  
98 -Packages=vcl;rtl;vclx;indy;inet;xmlrtl;vclie;inetdbbde;inetdbxpress;dbrtl;dsnap;dsnapcon;vcldb;soaprtl;VclSmp;dbexpress;dbxcds;inetdb;bdertl;vcldbx;webdsnap;websnap;adortl;ibxpress;teeui;teedb;tee;dss;visualclx;visualdbclx;vclactnband;vclshlctrls;IntrawebDB_50_70;Intraweb_50_70;Rave50CLX;Rave50VCL;dclOffice2k;MSI_D7_Rtl  
99 -Conditionals=  
100 -DebugSourceDirs=  
101 -UsePackages=0  
102 -[Parameters]  
103 -RunParams=  
104 -HostApplication=  
105 -Launcher=  
106 -UseLauncher=0  
107 -DebugCWD=  
108 -[Language]  
109 -ActiveLang=  
110 -ProjectLang=  
111 -RootDir=C:\Arquivos de programas\Borland\Delphi7\Bin\  
112 -[Version Info]  
113 -IncludeVerInfo=1  
114 -AutoIncBuild=0  
115 -MajorVer=2  
116 -MinorVer=5  
117 -Release=0  
118 -Build=773  
119 -Debug=0  
120 -PreRelease=0  
121 -Special=0  
122 -Private=0  
123 -DLL=0  
124 -Locale=1046  
125 -CodePage=1252  
126 -[Version Info Keys]  
127 -CompanyName=Dataprev - Emp. de TI da Prev.Social - URES  
128 -FileDescription=Coletor de Informações de Patrimônio do Sistema CACIC  
129 -FileVersion=2.5.0.773  
130 -InternalName=  
131 -LegalCopyright=  
132 -LegalTrademarks=  
133 -OriginalFilename=  
134 -ProductName=Col_PATR  
135 -ProductVersion=2.6  
136 -Comments=Baseado na Licença GPL(General Public License)  
col_patr/col_patr.dpr
@@ -1,60 +0,0 @@ @@ -1,60 +0,0 @@
1 -(**  
2 ----------------------------------------------------------------------------------------------------------------------------------------------------------------  
3 -Copyright 2000, 2001, 2002, 2003, 2004, 2005 Dataprev - Empresa de Tecnologia e Informações da Previdência Social, Brasil  
4 -  
5 -Este arquivo é parte do programa CACIC - Configurador Automático e Coletor de Informações Computacionais  
6 -  
7 -O CACIC é um software livre; você pode redistribui-lo e/ou modifica-lo dentro dos termos da Licença Pública Geral GNU como  
8 -publicada pela Fundação do Software Livre (FSF); na versão 2 da Licença, ou (na sua opinião) qualquer versão.  
9 -  
10 -Este programa é distribuido na esperança que possa ser util, mas SEM NENHUMA GARANTIA; sem uma garantia implicita de ADEQUAÇÂO a qualquer  
11 -MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU para maiores detalhes.  
12 -  
13 -Você deve ter recebido uma cópia da Licença Pública Geral GNU, sob o título "LICENCA.txt", junto com este programa, se não, escreva para a Fundação do Software  
14 -Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA  
15 ----------------------------------------------------------------------------------------------------------------------------------------------------------------  
16 -*)  
17 -  
18 -program col_patr;  
19 -  
20 -uses  
21 - Forms,  
22 - Windows,  
23 - main_col_patr in 'main_col_patr.pas' {FormPatrimonio},  
24 - LibXmlParser,  
25 - XML,  
26 - CACIC_Library in '..\CACIC_Library.pas';  
27 -  
28 -{$R *.res}  
29 -  
30 -const  
31 - CACIC_APP_NAME = 'col_patr';  
32 -  
33 -var  
34 - hwind:HWND;  
35 - oCacic : TCACIC;  
36 -  
37 -begin  
38 - oCacic := TCACIC.Create();  
39 -  
40 - if( oCacic.isAppRunning( CACIC_APP_NAME ) )  
41 - then begin  
42 - hwind := 0;  
43 - repeat // The string 'My app' must match your App Title (below)  
44 - hwind:=Windows.FindWindowEx(0,hwind,'TApplication', CACIC_APP_NAME );  
45 - until (hwind<>Application.Handle);  
46 - IF (hwind<>0) then  
47 - begin  
48 - Windows.ShowWindow(hwind,SW_SHOWNORMAL);  
49 - Windows.SetForegroundWindow(hwind);  
50 - end;  
51 - end  
52 - else begin  
53 - Application.Initialize;  
54 - Application.CreateForm(TFormPatrimonio, FormPatrimonio);  
55 - Application.Run;  
56 - end;  
57 -  
58 - oCacic.Free();  
59 -  
60 -end.  
col_patr/col_patr.res
No preview for this file type
col_patr/col_patr_icon.ico
No preview for this file type
col_patr/frmPatrimonio.ddp
No preview for this file type
col_patr/frmPatrimonio.dfm
@@ -1,358 +0,0 @@ @@ -1,358 +0,0 @@
1 -object FormPatrimonio: TFormPatrimonio  
2 - Left = 153  
3 - Top = 162  
4 - BorderIcons = [biSystemMenu]  
5 - BorderStyle = bsSingle  
6 - Caption = 'Coleta de Informa'#231#245'es de Patrim'#244'nio'  
7 - ClientHeight = 246  
8 - ClientWidth = 516  
9 - Color = clBtnFace  
10 - Font.Charset = DEFAULT_CHARSET  
11 - Font.Color = clWindowText  
12 - Font.Height = -11  
13 - Font.Name = 'MS Sans Serif'  
14 - Font.Style = []  
15 - OldCreateOrder = False  
16 - OnClose = FormClose  
17 - OnCreate = FormCreate  
18 - PixelsPerInch = 96  
19 - TextHeight = 13  
20 - object GroupBox1: TGroupBox  
21 - Left = 5  
22 - Top = -1  
23 - Width = 505  
24 - Height = 67  
25 - Caption = ' Leia com aten'#231#227'o '  
26 - Color = clBtnFace  
27 - Font.Charset = DEFAULT_CHARSET  
28 - Font.Color = clRed  
29 - Font.Height = -13  
30 - Font.Name = 'MS Sans Serif'  
31 - Font.Style = [fsBold]  
32 - ParentColor = False  
33 - ParentFont = False  
34 - TabOrder = 0  
35 - object Label10: TLabel  
36 - Left = 5  
37 - Top = 14  
38 - Width = 498  
39 - Height = 32  
40 - AutoSize = False  
41 - Caption =  
42 - 'O preenchimento correto dos campos abaixo '#233' de extrema import'#226'nc' +  
43 - 'ia para um efetivo controle patrimonial e localiza'#231#227'o de equipam' +  
44 - 'entos.'  
45 - Font.Charset = DEFAULT_CHARSET  
46 - Font.Color = clBlack  
47 - Font.Height = -13  
48 - Font.Name = 'MS Sans Serif'  
49 - Font.Style = []  
50 - ParentFont = False  
51 - WordWrap = True  
52 - end  
53 - object Label11: TLabel  
54 - Left = 6  
55 - Top = 46  
56 - Width = 456  
57 - Height = 16  
58 - Caption =  
59 - 'Por favor, atualize as informa'#231#245'es abaixo. Agradecemos a sua col' +  
60 - 'abora'#231#227'o.'  
61 - Color = clBtnFace  
62 - Font.Charset = DEFAULT_CHARSET  
63 - Font.Color = clBlack  
64 - Font.Height = -13  
65 - Font.Name = 'MS Sans Serif'  
66 - Font.Style = []  
67 - ParentColor = False  
68 - ParentFont = False  
69 - end  
70 - end  
71 - object GroupBox2: TGroupBox  
72 - Left = 5  
73 - Top = 69  
74 - Width = 506  
75 - Height = 144  
76 - Caption = ' Informa'#231#245'es sobre este computador '  
77 - Font.Charset = DEFAULT_CHARSET  
78 - Font.Color = clBlue  
79 - Font.Height = -11  
80 - Font.Name = 'MS Sans Serif'  
81 - Font.Style = [fsBold]  
82 - ParentFont = False  
83 - TabOrder = 1  
84 - object Etiqueta1: TLabel  
85 - Left = 11  
86 - Top = 17  
87 - Width = 48  
88 - Height = 13  
89 - Caption = 'Etiqueta 1'  
90 - Font.Charset = DEFAULT_CHARSET  
91 - Font.Color = clWindowText  
92 - Font.Height = -11  
93 - Font.Name = 'MS Sans Serif'  
94 - Font.Style = []  
95 - ParentFont = False  
96 - end  
97 - object Etiqueta2: TLabel  
98 - Left = 175  
99 - Top = 17  
100 - Width = 48  
101 - Height = 13  
102 - Caption = 'Etiqueta 2'  
103 - Font.Charset = DEFAULT_CHARSET  
104 - Font.Color = clWindowText  
105 - Font.Height = -11  
106 - Font.Name = 'MS Sans Serif'  
107 - Font.Style = []  
108 - ParentFont = False  
109 - end  
110 - object Etiqueta3: TLabel  
111 - Left = 342  
112 - Top = 17  
113 - Width = 48  
114 - Height = 13  
115 - Caption = 'Etiqueta 3'  
116 - Font.Charset = DEFAULT_CHARSET  
117 - Font.Color = clWindowText  
118 - Font.Height = -11  
119 - Font.Name = 'MS Sans Serif'  
120 - Font.Style = []  
121 - ParentFont = False  
122 - end  
123 - object Etiqueta4: TLabel  
124 - Left = 11  
125 - Top = 57  
126 - Width = 48  
127 - Height = 13  
128 - Caption = 'Etiqueta 4'  
129 - Font.Charset = DEFAULT_CHARSET  
130 - Font.Color = clWindowText  
131 - Font.Height = -11  
132 - Font.Name = 'MS Sans Serif'  
133 - Font.Style = []  
134 - ParentFont = False  
135 - end  
136 - object Etiqueta5: TLabel  
137 - Left = 178  
138 - Top = 57  
139 - Width = 48  
140 - Height = 13  
141 - Caption = 'Etiqueta 5'  
142 - Font.Charset = DEFAULT_CHARSET  
143 - Font.Color = clWindowText  
144 - Font.Height = -11  
145 - Font.Name = 'MS Sans Serif'  
146 - Font.Style = []  
147 - ParentFont = False  
148 - end  
149 - object Etiqueta6: TLabel  
150 - Left = 343  
151 - Top = 57  
152 - Width = 48  
153 - Height = 13  
154 - Caption = 'Etiqueta 6'  
155 - Font.Charset = DEFAULT_CHARSET  
156 - Font.Color = clWindowText  
157 - Font.Height = -11  
158 - Font.Name = 'MS Sans Serif'  
159 - Font.Style = []  
160 - ParentFont = False  
161 - end  
162 - object Etiqueta7: TLabel  
163 - Left = 11  
164 - Top = 98  
165 - Width = 48  
166 - Height = 13  
167 - Caption = 'Etiqueta 7'  
168 - Font.Charset = DEFAULT_CHARSET  
169 - Font.Color = clWindowText  
170 - Font.Height = -11  
171 - Font.Name = 'MS Sans Serif'  
172 - Font.Style = []  
173 - ParentFont = False  
174 - end  
175 - object Etiqueta8: TLabel  
176 - Left = 178  
177 - Top = 98  
178 - Width = 48  
179 - Height = 13  
180 - Caption = 'Etiqueta 8'  
181 - Font.Charset = DEFAULT_CHARSET  
182 - Font.Color = clWindowText  
183 - Font.Height = -11  
184 - Font.Name = 'MS Sans Serif'  
185 - Font.Style = []  
186 - ParentFont = False  
187 - end  
188 - object Etiqueta9: TLabel  
189 - Left = 343  
190 - Top = 98  
191 - Width = 48  
192 - Height = 13  
193 - Caption = 'Etiqueta 9'  
194 - Font.Charset = DEFAULT_CHARSET  
195 - Font.Color = clWindowText  
196 - Font.Height = -11  
197 - Font.Name = 'MS Sans Serif'  
198 - Font.Style = []  
199 - ParentFont = False  
200 - end  
201 - object id_unid_organizacional_nivel1: TComboBox  
202 - Left = 9  
203 - Top = 31  
204 - Width = 157  
205 - Height = 21  
206 - Hint = 'Esse '#233' o texto de ajuda da "Etiqueta 1"'  
207 - Style = csDropDownList  
208 - Font.Charset = DEFAULT_CHARSET  
209 - Font.Color = clWindowText  
210 - Font.Height = -11  
211 - Font.Name = 'MS Sans Serif'  
212 - Font.Style = []  
213 - ItemHeight = 13  
214 - ParentFont = False  
215 - ParentShowHint = False  
216 - ShowHint = True  
217 - TabOrder = 0  
218 - OnChange = id_unid_organizacional_nivel1Change  
219 - end  
220 - object id_unid_organizacional_nivel2: TComboBox  
221 - Left = 175  
222 - Top = 31  
223 - Width = 157  
224 - Height = 21  
225 - Style = csDropDownList  
226 - Font.Charset = DEFAULT_CHARSET  
227 - Font.Color = clWindowText  
228 - Font.Height = -11  
229 - Font.Name = 'MS Sans Serif'  
230 - Font.Style = []  
231 - ItemHeight = 13  
232 - ParentFont = False  
233 - ParentShowHint = False  
234 - ShowHint = True  
235 - TabOrder = 1  
236 - end  
237 - object te_localizacao_complementar: TEdit  
238 - Left = 341  
239 - Top = 31  
240 - Width = 157  
241 - Height = 21  
242 - Font.Charset = DEFAULT_CHARSET  
243 - Font.Color = clWindowText  
244 - Font.Height = -11  
245 - Font.Name = 'MS Sans Serif'  
246 - Font.Style = []  
247 - ParentFont = False  
248 - ParentShowHint = False  
249 - ShowHint = True  
250 - TabOrder = 2  
251 - end  
252 - object te_info_patrimonio3: TEdit  
253 - Left = 342  
254 - Top = 71  
255 - Width = 155  
256 - Height = 21  
257 - Font.Charset = DEFAULT_CHARSET  
258 - Font.Color = clWindowText  
259 - Font.Height = -11  
260 - Font.Name = 'MS Sans Serif'  
261 - Font.Style = []  
262 - ParentFont = False  
263 - ParentShowHint = False  
264 - ShowHint = True  
265 - TabOrder = 5  
266 - end  
267 - object te_info_patrimonio1: TEdit  
268 - Left = 9  
269 - Top = 71  
270 - Width = 158  
271 - Height = 21  
272 - Font.Charset = DEFAULT_CHARSET  
273 - Font.Color = clWindowText  
274 - Font.Height = -11  
275 - Font.Name = 'MS Sans Serif'  
276 - Font.Style = []  
277 - ParentFont = False  
278 - ParentShowHint = False  
279 - ShowHint = True  
280 - TabOrder = 3  
281 - end  
282 - object te_info_patrimonio2: TEdit  
283 - Left = 177  
284 - Top = 71  
285 - Width = 155  
286 - Height = 21  
287 - Font.Charset = DEFAULT_CHARSET  
288 - Font.Color = clWindowText  
289 - Font.Height = -11  
290 - Font.Name = 'MS Sans Serif'  
291 - Font.Style = []  
292 - ParentFont = False  
293 - ParentShowHint = False  
294 - ShowHint = True  
295 - TabOrder = 4  
296 - end  
297 - object te_info_patrimonio6: TEdit  
298 - Left = 342  
299 - Top = 112  
300 - Width = 155  
301 - Height = 21  
302 - Font.Charset = DEFAULT_CHARSET  
303 - Font.Color = clWindowText  
304 - Font.Height = -11  
305 - Font.Name = 'MS Sans Serif'  
306 - Font.Style = []  
307 - ParentFont = False  
308 - ParentShowHint = False  
309 - ShowHint = True  
310 - TabOrder = 8  
311 - end  
312 - object te_info_patrimonio4: TEdit  
313 - Left = 9  
314 - Top = 112  
315 - Width = 158  
316 - Height = 21  
317 - Font.Charset = DEFAULT_CHARSET  
318 - Font.Color = clWindowText  
319 - Font.Height = -11  
320 - Font.Name = 'MS Sans Serif'  
321 - Font.Style = []  
322 - ParentFont = False  
323 - ParentShowHint = False  
324 - ShowHint = True  
325 - TabOrder = 6  
326 - end  
327 - object te_info_patrimonio5: TEdit  
328 - Left = 177  
329 - Top = 112  
330 - Width = 155  
331 - Height = 21  
332 - Font.Charset = DEFAULT_CHARSET  
333 - Font.Color = clWindowText  
334 - Font.Height = -11  
335 - Font.Name = 'MS Sans Serif'  
336 - Font.Style = []  
337 - ParentFont = False  
338 - ParentShowHint = False  
339 - ShowHint = True  
340 - TabOrder = 7  
341 - end  
342 - end  
343 - object Button2: TButton  
344 - Left = 352  
345 - Top = 219  
346 - Width = 159  
347 - Height = 23  
348 - Caption = 'Gravar Informa'#231#245'es'  
349 - Font.Charset = DEFAULT_CHARSET  
350 - Font.Color = clWindowText  
351 - Font.Height = -11  
352 - Font.Name = 'MS Sans Serif'  
353 - Font.Style = [fsBold]  
354 - ParentFont = False  
355 - TabOrder = 2  
356 - OnClick = AtualizaPatrimonio  
357 - end  
358 -end  
col_patr/frmPatrimonio.pas
@@ -1,458 +0,0 @@ @@ -1,458 +0,0 @@
1 -unit frmPatrimonio;  
2 -  
3 -interface  
4 -  
5 -uses  
6 - Windows, StdCtrls, Controls, Classes, Forms;  
7 -  
8 -type  
9 - TFormPatrimonio = class(TForm)  
10 - GroupBox1: TGroupBox;  
11 - Label10: TLabel;  
12 - Label11: TLabel;  
13 - GroupBox2: TGroupBox;  
14 - Etiqueta1: TLabel;  
15 - Etiqueta2: TLabel;  
16 - Etiqueta3: TLabel;  
17 - id_unid_organizacional_nivel1: TComboBox;  
18 - id_unid_organizacional_nivel2: TComboBox;  
19 - te_localizacao_complementar: TEdit;  
20 - Button2: TButton;  
21 - Etiqueta4: TLabel;  
22 - Etiqueta5: TLabel;  
23 - Etiqueta6: TLabel;  
24 - Etiqueta7: TLabel;  
25 - Etiqueta8: TLabel;  
26 - Etiqueta9: TLabel;  
27 - te_info_patrimonio3: TEdit;  
28 - te_info_patrimonio1: TEdit;  
29 - te_info_patrimonio2: TEdit;  
30 - te_info_patrimonio6: TEdit;  
31 - te_info_patrimonio4: TEdit;  
32 - te_info_patrimonio5: TEdit;  
33 -  
34 - procedure FormCreate(Sender: TObject);  
35 - procedure MontaCombos;  
36 - procedure MontaInterface;  
37 - procedure FormClose(Sender: TObject; var Action: TCloseAction);  
38 - procedure id_unid_organizacional_nivel1Change(Sender: TObject);  
39 - procedure AtualizaPatrimonio(Sender: TObject);  
40 - procedure RecuperaValoresAnteriores;  
41 - private  
42 - var_id_unid_organizacional_nivel1, var_id_unid_organizacional_nivel2, var_te_localizacao_complementar,  
43 - var_te_info_patrimonio1, var_te_info_patrimonio2, var_te_info_patrimonio3, var_te_info_patrimonio4,  
44 - var_te_info_patrimonio5, var_te_info_patrimonio6,  
45 - var_dt_hr_alteracao_patrim_interface, var_dt_hr_alteracao_patrim_uon1, var_dt_hr_alteracao_patrim_uon2 : String;  
46 -  
47 - public  
48 - { Public declarations }  
49 - end;  
50 -  
51 -var  
52 - FormPatrimonio: TFormPatrimonio;  
53 -  
54 -implementation  
55 -  
56 -{$R *.dfm}  
57 -  
58 -  
59 -// Estruturas de dados para armazenar os itens da uon1 e uon2  
60 -type  
61 - TRegistroUON1 = record  
62 - id1 : String;  
63 - valor : String;  
64 - end;  
65 - TVetorUON1 = array of TRegistroUON1;  
66 -  
67 - TRegistroUON2 = record  
68 - id1 : String;  
69 - id2 : String;  
70 - valor : String;  
71 - end;  
72 - TVetorUON2 = array of TRegistroUON2;  
73 -  
74 -var VetorUON1 : TVetorUON1;  
75 - VetorUON2 : TVetorUON2;  
76 -  
77 - // Esse array é usado apenas para saber a uon2, após a filtragem pelo uon1  
78 - VetorUON2Filtrado : array of String;  
79 -  
80 -  
81 -Function RetornaValorVetorUON1(id1Procurado1 : string) : String;  
82 -var I : Integer;  
83 -begin  
84 - For I := 0 to (Length(VetorUON1)-1) Do  
85 - If (VetorUON1[I].id1 = id1Procurado1) Then Result := VetorUON1[I].valor;  
86 -end;  
87 -  
88 -  
89 -Function RetornaValorVetorUON2(id1Procurado : string; id2Procurado : string) : String;  
90 -var I : Integer;  
91 -begin  
92 - For I := 0 to (Length(VetorUON2)-1) Do  
93 - If (VetorUON2[I].id1 = id1Procurado) and (VetorUON2[I].id2 = id2Procurado) Then Result := VetorUON2[I].valor;  
94 -end;  
95 -  
96 -  
97 -  
98 -procedure TFormPatrimonio.FormCreate(Sender: TObject);  
99 -var Request_PAT: TStringList ; strRetorno: string;  
100 -Begin  
101 - //Recuperar valores abaixo do INI...  
102 - {  
103 - Request_PAT := TStringList.Create;  
104 - Request_PAT.Values['te_node_address'] := TE_NODE_ADDRESS;  
105 - Request_PAT.Values['id_so'] := ID_SO;  
106 - Request_PAT.Values['id_ip_rede'] := ID_IP_REDE;  
107 - Request_PAT.Values['te_nome_computador'] := TE_NOME_COMPUTADOR;  
108 - Request_PAT.Values['te_ip'] := TE_IP;  
109 - Request_PAT.Values['te_workgroup'] := TE_WORKGROUP;  
110 -  
111 -  
112 -  
113 -// strRetorno := comunicacao.ComunicaServidor('get_patrimonio.php?tipo=dua', Nil, '<< Obtendo as datas de alteração das configurações de patrimônio.');  
114 - strRetorno := comunicacao.ComunicaServidor('get_patrimonio.php?tipo=dua', Request_PAT, '<< Obtendo as datas de alteração das configurações de patrimônio.');  
115 -  
116 - // Antes não liberava...  
117 - Request_PAT.Free;  
118 - }  
119 - strRetorno := '0';  
120 - if (strRetorno <> '0') Then  
121 - begin  
122 - //Vejo as datas de alteração da interface e da uon1 e uon2.  
123 - {  
124 - Pegar do INI  
125 - var_dt_hr_alteracao_patrim_interface := XML.XML_RetornaValor('dt_hr_alteracao_patrim_interface', strRetorno);  
126 - var_dt_hr_alteracao_patrim_uon1 := XML.XML_RetornaValor('dt_hr_alteracao_patrim_uon1', strRetorno);  
127 - var_dt_hr_alteracao_patrim_uon2 := XML.XML_RetornaValor('dt_hr_alteracao_patrim_uon2', strRetorno);  
128 - }  
129 -  
130 - MontaInterface;  
131 - MontaCombos;  
132 - RecuperaValoresAnteriores;  
133 - end;  
134 -  
135 -end;  
136 -  
137 -  
138 -  
139 -  
140 -procedure TFormPatrimonio.RecuperaValoresAnteriores;  
141 -begin  
142 - var_id_unid_organizacional_nivel1 := GetValorChaveRegIni('Patrimonio','id_unid_organizacional_nivel1', p_path_cacic_ini);  
143 - var_id_unid_organizacional_nivel2 := registro.GetValorChaveRegIni('Patrimonio','id_unid_organizacional_nivel2', p_path_cacic_ini);  
144 - var_te_localizacao_complementar := registro.GetValorChaveRegIni('Patrimonio','te_localizacao_complementar', p_path_cacic_ini);  
145 - var_te_info_patrimonio1 := registro.GetValorChaveRegIni('Patrimonio','te_info_patrimonio1', p_path_cacic_ini);  
146 - var_te_info_patrimonio2 := registro.GetValorChaveRegIni('Patrimonio','te_info_patrimonio2', p_path_cacic_ini);  
147 - var_te_info_patrimonio3 := registro.GetValorChaveRegIni('Patrimonio','te_info_patrimonio3', p_path_cacic_ini);  
148 - var_te_info_patrimonio4 := registro.GetValorChaveRegIni('Patrimonio','te_info_patrimonio4', p_path_cacic_ini);  
149 - var_te_info_patrimonio5 := registro.GetValorChaveRegIni('Patrimonio','te_info_patrimonio5', p_path_cacic_ini);  
150 - var_te_info_patrimonio6 := registro.GetValorChaveRegIni('Patrimonio','te_info_patrimonio6', p_path_cacic_ini);  
151 -  
152 - Try  
153 - id_unid_organizacional_nivel1.ItemIndex := id_unid_organizacional_nivel1.Items.IndexOf(RetornaValorVetorUON1(var_id_unid_organizacional_nivel1));  
154 - id_unid_organizacional_nivel1Change(Nil); // Para filtrar os valores do combo2 de acordo com o valor selecionado no combo1  
155 - id_unid_organizacional_nivel2.ItemIndex := id_unid_organizacional_nivel2.Items.IndexOf(RetornaValorVetorUON2(var_id_unid_organizacional_nivel1, var_id_unid_organizacional_nivel2));  
156 - Except  
157 - end;  
158 - te_localizacao_complementar.Text := var_te_localizacao_complementar;  
159 - te_info_patrimonio1.Text := var_te_info_patrimonio1;  
160 - te_info_patrimonio2.Text := var_te_info_patrimonio2;  
161 - te_info_patrimonio3.Text := var_te_info_patrimonio3;  
162 - te_info_patrimonio4.Text := var_te_info_patrimonio4;  
163 - te_info_patrimonio5.Text := var_te_info_patrimonio5;  
164 - te_info_patrimonio6.Text := var_te_info_patrimonio6;  
165 -end;  
166 -  
167 -  
168 -  
169 -procedure TFormPatrimonio.MontaCombos;  
170 -var strRetorno, strAux, strItensUON1Registro, strItensUON2Registro : String;  
171 - Parser : TXmlParser;  
172 - i : integer;  
173 -begin  
174 - // Código para montar o combo 1  
175 - // Se houve alteração na configuração da uon1, atualizo os dados no registro e depois monto a interface.  
176 - // Caso, contrário, pego direto do registro.  
177 - strItensUON1Registro := Registro.GetValorChaveRegIni('Patrimonio','itens_uon1', p_path_cacic_ini);  
178 - strAux := registro.GetValorChaveRegIni('Patrimonio','dt_hr_alteracao_patrim_uon1', p_path_cacic_ini);  
179 - If (Trim(strItensUON1Registro) = '') or (Trim(var_dt_hr_alteracao_patrim_uon1) = '') or (Trim(strAux) = '') or (var_dt_hr_alteracao_patrim_uon1 <> strAux) Then  
180 - Begin  
181 - strRetorno := comunicacao.ComunicaServidor('get_patrimonio.php?tipo=itens_uon1', Nil, '<< Obtendo os itens da Tabela de Unidade Organizacional Nível 1 a partir do servidor.');  
182 - if (strRetorno <> '0') Then  
183 - begin  
184 - // Gravo no registro a dt_hr_alteracao_patrim_uon1, obtida a partir do bd, para posterior comparação.  
185 - Registro.SetValorChaveRegIni('Patrimonio','dt_hr_alteracao_patrim_uon1', var_dt_hr_alteracao_patrim_uon1, p_path_cacic_ini);  
186 - Registro.SetValorChaveRegIni('Patrimonio','itens_uon1', strRetorno, p_path_cacic_ini);  
187 - end;  
188 - end  
189 - Else strRetorno := strItensUON1Registro;  
190 -  
191 - Parser := TXmlParser.Create;  
192 - Parser.Normalize := True;  
193 - Parser.LoadFromBuffer(PAnsiChar(strRetorno));  
194 - Parser.StartScan;  
195 - i := -1;  
196 - While Parser.Scan DO  
197 - Begin  
198 - if ((Parser.CurPartType = ptStartTag) and (UpperCase(Parser.CurName) = UpperCase('ITEM'))) Then  
199 - Begin  
200 - i := i + 1;  
201 - SetLength(VetorUON1, i + 1); // Aumento o tamanho da matriz dinamicamente de acordo com o número de itens recebidos.  
202 - end  
203 - else if (Parser.CurPartType in [ptContent, ptCData]) Then  
204 - begin  
205 - if (UpperCase(Parser.CurName) = UpperCase('ID1')) then VetorUON1[i].id1 := Parser.CurContent  
206 - else if (UpperCase(Parser.CurName) = UpperCase('VALOR')) then VetorUON1[i].valor := Parser.CurContent  
207 - end  
208 - end;  
209 -  
210 -  
211 - // Código para montar o combo 2  
212 - // Se houve alteração na configuração da uon2, atualizo os dados no registro e depois monto a interface.  
213 - // Caso, contrário, pego direto do registro.  
214 - strItensUON2Registro := registro.GetValorChaveRegIni('Patrimonio','itens_uon2', p_path_cacic_ini);  
215 - strAux := registro.GetValorChaveRegIni('Patrimonio','dt_hr_alteracao_patrim_uon2', p_path_cacic_ini);  
216 - If (Trim(strItensUON2Registro) = '') or (Trim(var_dt_hr_alteracao_patrim_uon2) = '') or (Trim(strAux) = '') or (var_dt_hr_alteracao_patrim_uon2 <> strAux) Then  
217 - Begin  
218 - strRetorno := comunicacao.ComunicaServidor('get_patrimonio.php?tipo=itens_uon2', Nil, '<< Obtendo os itens da Tabela de Unidade Organizacional Nível 2 a partir do servidor.');  
219 - if (strRetorno <> '0') Then  
220 - begin  
221 - // Gravo no registro a dt_hr_alteracao_patrim_uon2, obtida a partir do bd, para posterior comparação.  
222 - Registro.SetValorChaveRegIni('Patrimonio','dt_hr_alteracao_patrim_uon2', var_dt_hr_alteracao_patrim_uon2, p_path_cacic_ini);  
223 - Registro.SetValorChaveRegIni('Patrimonio','itens_uon2', strRetorno, p_path_cacic_ini);  
224 - end;  
225 - end  
226 - Else strRetorno := strItensUON2Registro;  
227 -  
228 - Parser.LoadFromBuffer(PAnsiChar(strRetorno));  
229 - Parser.StartScan;  
230 -  
231 - i := -1;  
232 - While Parser.Scan DO  
233 - Begin  
234 - if ((Parser.CurPartType = ptStartTag) and (UpperCase(Parser.CurName) = UpperCase('ITEM'))) Then  
235 - Begin  
236 - i := i + 1;  
237 - SetLength(VetorUON2, i + 1); // Aumento o tamanho da matriz dinamicamente de acordo com o número de itens recebidos.  
238 - end  
239 - else if (Parser.CurPartType in [ptContent, ptCData]) Then  
240 - begin  
241 - if (UpperCase(Parser.CurName) = UpperCase('ID1')) then VetorUON2[i].id1 := Parser.CurContent  
242 - else if (UpperCase(Parser.CurName) = UpperCase('ID2')) then VetorUON2[i].id2 := Parser.CurContent  
243 - else if (UpperCase(Parser.CurName) = UpperCase('VALOR')) then VetorUON2[i].valor := Parser.CurContent  
244 - end  
245 - end;  
246 -  
247 - Parser.Free;  
248 -  
249 - // Como os itens do combo1 nunca mudam durante a execução do programa (ao contrario do combo2), posso colocar o seu preenchimento aqui mesmo.  
250 - id_unid_organizacional_nivel1.Items.Clear;  
251 - For i := 0 to Length(VetorUON1) - 1 Do  
252 - id_unid_organizacional_nivel1.Items.Add(VetorUON1[i].valor);  
253 -  
254 -end;  
255 -  
256 -  
257 -  
258 -procedure TFormPatrimonio.id_unid_organizacional_nivel1Change(Sender: TObject);  
259 -var i, j: Word;  
260 - strAux : String;  
261 -begin  
262 - // Filtro os itens do combo2, de acordo com o item selecionado no combo1  
263 - strAux := VetorUON1[id_unid_organizacional_nivel1.ItemIndex].id1;  
264 - id_unid_organizacional_nivel2.Items.Clear;  
265 - SetLength(VetorUON2Filtrado, 0);  
266 - For i := 0 to Length(VetorUON2) - 1 Do  
267 - Begin  
268 - if VetorUON2[i].id1 = strAux then  
269 - Begin  
270 - id_unid_organizacional_nivel2.Items.Add(VetorUON2[i].valor);  
271 - j := Length(VetorUON2Filtrado);  
272 - SetLength(VetorUON2Filtrado, j + 1);  
273 - VetorUON2Filtrado[j] := VetorUON2[i].id2;  
274 - end;  
275 - end;  
276 -end;  
277 -  
278 -  
279 -procedure TFormPatrimonio.AtualizaPatrimonio(Sender: TObject);  
280 -var Request_ATPAT: TStringList;  
281 - strAux1, strAux2 : String;  
282 -begin  
283 - //Verifico se houve qualquer alteração nas informações.  
284 - // Só vou enviar as novas informações para o bd ou gravar no registro se houve alterações.  
285 - Try  
286 - strAux1 := VetorUON1[id_unid_organizacional_nivel1.ItemIndex].id1;  
287 - strAux2 := VetorUON2Filtrado[id_unid_organizacional_nivel2.ItemIndex];  
288 - Except  
289 - end;  
290 - if (strAux1 <> var_id_unid_organizacional_nivel1) or  
291 - (strAux2 <> var_id_unid_organizacional_nivel2) or  
292 - (te_localizacao_complementar.Text <> var_te_localizacao_complementar) or  
293 - (te_info_patrimonio1.Text <> var_te_info_patrimonio1) or  
294 - (te_info_patrimonio2.Text <> var_te_info_patrimonio2) or  
295 - (te_info_patrimonio3.Text <> var_te_info_patrimonio3) or  
296 - (te_info_patrimonio4.Text <> var_te_info_patrimonio4) or  
297 - (te_info_patrimonio5.Text <> var_te_info_patrimonio5) or  
298 - (te_info_patrimonio6.Text <> var_te_info_patrimonio6) then  
299 - begin  
300 - //Envio via rede para ao Agente Gerente, para gravação no BD.  
301 - Request_ATPAT:=TStringList.Create;  
302 - Request_ATPAT.Values['te_node_address'] := TE_NODE_ADDRESS;  
303 - Request_ATPAT.Values['id_so'] := ID_SO;  
304 - Request_ATPAT.Values['te_nome_computador'] := TE_NOME_COMPUTADOR;  
305 - Request_ATPAT.Values['te_nome_host'] := TE_NOME_HOST;  
306 - Request_ATPAT.Values['id_ip_rede'] := ID_IP_REDE;  
307 - Request_ATPAT.Values['te_ip'] := TE_IP;  
308 - Request_ATPAT.Values['te_workgroup'] := TE_WORKGROUP;  
309 - Request_ATPAT.Values['id_unid_organizacional_nivel1'] := strAux1;  
310 - Request_ATPAT.Values['id_unid_organizacional_nivel2'] := strAux2;  
311 - Request_ATPAT.Values['te_localizacao_complementar'] := te_localizacao_complementar.Text;  
312 - Request_ATPAT.Values['te_info_patrimonio1'] := te_info_patrimonio1.Text;  
313 - Request_ATPAT.Values['te_info_patrimonio2'] := te_info_patrimonio2.Text;  
314 - Request_ATPAT.Values['te_info_patrimonio3'] := te_info_patrimonio3.Text;  
315 - Request_ATPAT.Values['te_info_patrimonio4'] := te_info_patrimonio4.Text;  
316 - Request_ATPAT.Values['te_info_patrimonio5'] := te_info_patrimonio5.Text;  
317 - Request_ATPAT.Values['te_info_patrimonio6'] := te_info_patrimonio6.Text;  
318 -  
319 - // Somente atualizo o registro caso não tenha havido nenhum erro durante o envio das informações para o BD  
320 - //Sobreponho a informação no registro para posterior comparação, na próxima execução.  
321 - if (comunicacao.ComunicaServidor('set_patrimonio.php', Request_ATPAT, '>> Enviando informações de patrimônio para o servidor.') <> '0') Then  
322 - Begin  
323 - Registro.SetValorChaveRegIni('Patrimonio','id_unid_organizacional_nivel1', strAux1, p_path_cacic_ini);  
324 - Registro.SetValorChaveRegIni('Patrimonio','id_unid_organizacional_nivel2', strAux2, p_path_cacic_ini);  
325 - Registro.SetValorChaveRegIni('Patrimonio','te_localizacao_complementar', te_localizacao_complementar.Text, p_path_cacic_ini);  
326 - Registro.SetValorChaveRegIni('Patrimonio','te_info_patrimonio1', te_info_patrimonio1.Text, p_path_cacic_ini);  
327 - Registro.SetValorChaveRegIni('Patrimonio','te_info_patrimonio2', te_info_patrimonio2.Text, p_path_cacic_ini);  
328 - Registro.SetValorChaveRegIni('Patrimonio','te_info_patrimonio3', te_info_patrimonio3.Text, p_path_cacic_ini);  
329 - Registro.SetValorChaveRegIni('Patrimonio','te_info_patrimonio4', te_info_patrimonio4.Text, p_path_cacic_ini);  
330 - Registro.SetValorChaveRegIni('Patrimonio','te_info_patrimonio5', te_info_patrimonio5.Text, p_path_cacic_ini);  
331 - Registro.SetValorChaveRegIni('Patrimonio','te_info_patrimonio6', te_info_patrimonio6.Text, p_path_cacic_ini);  
332 - end;  
333 -  
334 - Request_ATPAT.Free;  
335 - end;  
336 -  
337 - registro.SetValorChaveRegIni('Patrimonio','ultima_rede_obtida', ID_IP_REDE, p_path_cacic_ini);  
338 - registro.SetValorChaveRegIni('Patrimonio','dt_ultima_renovacao_patrim', FormatDateTime('yyyymmdd', Date), p_path_cacic_ini);  
339 -  
340 - Close;  
341 -end;  
342 -  
343 -procedure TFormPatrimonio.MontaInterface;  
344 -var strAux, strRetorno: string;  
345 -Begin  
346 - // Se houve alteração na configuração da interface, atualizo os dados no registro e depois monto a interface.  
347 - // Caso, contrário, pego direto do registro.  
348 - strAux := registro.GetValorChaveRegIni('Patrimonio','dt_hr_alteracao_patrim_interface', p_path_cacic_ini);  
349 -  
350 - If ((var_dt_hr_alteracao_patrim_interface) = '') or (Trim(strAux) = '') or (var_dt_hr_alteracao_patrim_interface <> strAux) Then  
351 - Begin  
352 - strRetorno := comunicacao.ComunicaServidor('get_patrimonio.php?tipo=config', Nil, '<< Obtendo as configurações da tela de patrimônio a partir do servidor.');  
353 -  
354 - if (strRetorno <> '0') Then  
355 - begin  
356 - // Gravo no registro a dt_hr_alteracao_patrim_interface, obtida a partir do bd, para posterior comparação.  
357 - Registro.SetValorChaveRegIni('Patrimonio','config_interface', strRetorno, p_path_cacic_ini);  
358 - Registro.SetValorChaveRegIni('Patrimonio','dt_hr_alteracao_patrim_interface', var_dt_hr_alteracao_patrim_interface, p_path_cacic_ini);  
359 - end;  
360 - end  
361 - Else strRetorno := Registro.GetValorChaveRegIni('Patrimonio','config_interface', p_path_cacic_ini);  
362 -  
363 - Etiqueta1.Caption := XML.XML_RetornaValor('te_etiqueta1', strRetorno);  
364 - id_unid_organizacional_nivel1.Hint := XML.XML_RetornaValor('te_help_etiqueta1', strRetorno);  
365 -  
366 - Etiqueta2.Caption := XML.XML_RetornaValor('te_etiqueta2', strRetorno);  
367 - id_unid_organizacional_nivel2.Hint := XML.XML_RetornaValor('te_help_etiqueta2', strRetorno);  
368 -  
369 - Etiqueta3.Caption := XML.XML_RetornaValor('te_etiqueta3', strRetorno);  
370 - te_localizacao_complementar.Hint := XML.XML_RetornaValor('te_help_etiqueta3', strRetorno);  
371 -  
372 - if (XML.XML_RetornaValor('in_exibir_etiqueta4', strRetorno) = 'S') then  
373 - begin  
374 - Etiqueta4.Caption := XML.XML_RetornaValor('te_etiqueta4', strRetorno);  
375 - te_info_patrimonio1.Hint := XML.XML_RetornaValor('te_help_etiqueta4', strRetorno);  
376 - te_info_patrimonio1.visible := True;  
377 - end  
378 - else begin  
379 - Etiqueta4.Visible := False;  
380 - te_info_patrimonio1.visible := False;  
381 -  
382 - end;  
383 -  
384 - if (XML.XML_RetornaValor('in_exibir_etiqueta5', strRetorno) = 'S') then  
385 - begin  
386 - Etiqueta5.Caption := XML.XML_RetornaValor('te_etiqueta5', strRetorno);  
387 - te_info_patrimonio2.Hint := XML.XML_RetornaValor('te_help_etiqueta5', strRetorno);  
388 - te_info_patrimonio2.visible := True;  
389 - end  
390 - else begin  
391 - Etiqueta5.Visible := False;  
392 - te_info_patrimonio2.visible := False;  
393 - end;  
394 -  
395 - if (XML.XML_RetornaValor('in_exibir_etiqueta6', strRetorno) = 'S') then  
396 - begin  
397 - Etiqueta6.Caption := XML.XML_RetornaValor('te_etiqueta6', strRetorno);  
398 - te_info_patrimonio3.Hint := XML.XML_RetornaValor('te_help_etiqueta6', strRetorno);  
399 - te_info_patrimonio3.visible := True;  
400 - end  
401 - else begin  
402 - Etiqueta6.Visible := False;  
403 - te_info_patrimonio3.visible := False;  
404 - end;  
405 -  
406 - if (XML.XML_RetornaValor('in_exibir_etiqueta7', strRetorno) = 'S') then  
407 - begin  
408 - Etiqueta7.Caption := XML.XML_RetornaValor('te_etiqueta7', strRetorno);  
409 - te_info_patrimonio4.Hint := XML.XML_RetornaValor('te_help_etiqueta7', strRetorno);  
410 - te_info_patrimonio4.visible := True;  
411 - end else  
412 - begin  
413 - Etiqueta7.Visible := False;  
414 - te_info_patrimonio4.visible := False;  
415 - end;  
416 -  
417 - if (XML.XML_RetornaValor('in_exibir_etiqueta8', strRetorno) = 'S') then  
418 - begin  
419 - Etiqueta8.Caption := XML.XML_RetornaValor('te_etiqueta8', strRetorno);  
420 - te_info_patrimonio5.Hint := XML.XML_RetornaValor('te_help_etiqueta8', strRetorno);  
421 - te_info_patrimonio5.visible := True;  
422 - end else  
423 - begin  
424 - Etiqueta8.Visible := False;  
425 - te_info_patrimonio5.visible := False;  
426 - end;  
427 -  
428 - if (XML.XML_RetornaValor('in_exibir_etiqueta9', strRetorno) = 'S') then  
429 - begin  
430 - Etiqueta9.Caption := XML.XML_RetornaValor('te_etiqueta9', strRetorno);  
431 - te_info_patrimonio6.Hint := XML.XML_RetornaValor('te_help_etiqueta9', strRetorno);  
432 - te_info_patrimonio6.visible := True;  
433 - end  
434 - else begin  
435 - Etiqueta9.Visible := False;  
436 - te_info_patrimonio6.visible := False;  
437 - end;  
438 -end;  
439 -  
440 -  
441 -  
442 -  
443 -  
444 -  
445 -  
446 -procedure TFormPatrimonio.FormClose(Sender: TObject; var Action: TCloseAction);  
447 -begin  
448 - //Teste Anderson  
449 -// FormPatrimonio := nil;  
450 - Action := cafree;  
451 -end;  
452 -  
453 -  
454 -  
455 -  
456 -  
457 -  
458 -end.  
col_patr/main_col_patr.ddp
No preview for this file type
col_patr/main_col_patr.dfm
@@ -1,425 +0,0 @@ @@ -1,425 +0,0 @@
1 -object FormPatrimonio: TFormPatrimonio  
2 - Left = 137  
3 - Top = 173  
4 - BorderIcons = [biSystemMenu]  
5 - BorderStyle = bsSingle  
6 - Caption = 'CACIC - Coletor de Informa'#231#245'es Patrimoniais'  
7 - ClientHeight = 286  
8 - ClientWidth = 782  
9 - Color = clBtnFace  
10 - Font.Charset = DEFAULT_CHARSET  
11 - Font.Color = clWindowText  
12 - Font.Height = -11  
13 - Font.Name = 'MS Sans Serif'  
14 - Font.Style = []  
15 - FormStyle = fsStayOnTop  
16 - OldCreateOrder = False  
17 - Position = poMainFormCenter  
18 - Visible = True  
19 - OnClose = FormClose  
20 - OnCreate = FormCreate  
21 - PixelsPerInch = 96  
22 - TextHeight = 13  
23 - object lbVersao: TLabel  
24 - Left = 672  
25 - Top = 273  
26 - Width = 108  
27 - Height = 12  
28 - Alignment = taRightJustify  
29 - AutoSize = False  
30 - Caption = 'v: X.X.X.X'  
31 - Font.Charset = DEFAULT_CHARSET  
32 - Font.Color = clWindowText  
33 - Font.Height = -9  
34 - Font.Name = 'Arial'  
35 - Font.Style = []  
36 - ParentFont = False  
37 - end  
38 - object GroupBox1: TGroupBox  
39 - Left = 2  
40 - Top = -1  
41 - Width = 780  
42 - Height = 75  
43 - Caption = ' Leia com aten'#231#227'o '  
44 - Color = clBtnFace  
45 - Font.Charset = DEFAULT_CHARSET  
46 - Font.Color = clRed  
47 - Font.Height = -13  
48 - Font.Name = 'MS Sans Serif'  
49 - Font.Style = [fsBold]  
50 - ParentColor = False  
51 - ParentFont = False  
52 - TabOrder = 0  
53 - object Label10: TLabel  
54 - Left = 5  
55 - Top = 14  
56 - Width = 769  
57 - Height = 32  
58 - AutoSize = False  
59 - Caption =  
60 - 'O preenchimento correto dos campos abaixo '#233' de extrema import'#226'nc' +  
61 - 'ia para um efetivo controle patrimonial e de localiza'#231#227'o de equi' +  
62 - 'pamentos.'  
63 - Font.Charset = DEFAULT_CHARSET  
64 - Font.Color = clBlack  
65 - Font.Height = -13  
66 - Font.Name = 'MS Sans Serif'  
67 - Font.Style = []  
68 - ParentFont = False  
69 - WordWrap = True  
70 - end  
71 - object Label11: TLabel  
72 - Left = 6  
73 - Top = 54  
74 - Width = 475  
75 - Height = 16  
76 - Caption =  
77 - 'Por favor, atualize as informa'#231#245'es abaixo. Agradecemos pela sua ' +  
78 - 'colabora'#231#227'o.'  
79 - Color = clBtnFace  
80 - Font.Charset = DEFAULT_CHARSET  
81 - Font.Color = clBlack  
82 - Font.Height = -13  
83 - Font.Name = 'MS Sans Serif'  
84 - Font.Style = []  
85 - ParentColor = False  
86 - ParentFont = False  
87 - end  
88 - end  
89 - object GroupBox2: TGroupBox  
90 - Left = 2  
91 - Top = 77  
92 - Width = 780  
93 - Height = 144  
94 - Caption =  
95 - 'Informa'#231#245'es sobre localiza'#231#227'o f'#237'sica e patrimonial deste computa' +  
96 - 'dor'  
97 - Font.Charset = DEFAULT_CHARSET  
98 - Font.Color = clBlue  
99 - Font.Height = -11  
100 - Font.Name = 'MS Sans Serif'  
101 - Font.Style = [fsBold]  
102 - ParentFont = False  
103 - TabOrder = 1  
104 - object Etiqueta1: TLabel  
105 - Left = 3  
106 - Top = 17  
107 - Width = 48  
108 - Height = 13  
109 - Caption = 'Etiqueta 1'  
110 - Font.Charset = DEFAULT_CHARSET  
111 - Font.Color = clWindowText  
112 - Font.Height = -11  
113 - Font.Name = 'MS Sans Serif'  
114 - Font.Style = []  
115 - ParentFont = False  
116 - end  
117 - object Etiqueta2: TLabel  
118 - Left = 3  
119 - Top = 101  
120 - Width = 48  
121 - Height = 13  
122 - Caption = 'Etiqueta 2'  
123 - Font.Charset = DEFAULT_CHARSET  
124 - Font.Color = clWindowText  
125 - Font.Height = -11  
126 - Font.Name = 'MS Sans Serif'  
127 - Font.Style = []  
128 - ParentFont = False  
129 - end  
130 - object Etiqueta3: TLabel  
131 - Left = 341  
132 - Top = 17  
133 - Width = 48  
134 - Height = 13  
135 - Caption = 'Etiqueta 3'  
136 - Font.Charset = DEFAULT_CHARSET  
137 - Font.Color = clWindowText  
138 - Font.Height = -11  
139 - Font.Name = 'MS Sans Serif'  
140 - Font.Style = []  
141 - ParentFont = False  
142 - end  
143 - object Etiqueta4: TLabel  
144 - Left = 341  
145 - Top = 59  
146 - Width = 48  
147 - Height = 13  
148 - Caption = 'Etiqueta 4'  
149 - Font.Charset = DEFAULT_CHARSET  
150 - Font.Color = clWindowText  
151 - Font.Height = -11  
152 - Font.Name = 'MS Sans Serif'  
153 - Font.Style = []  
154 - ParentFont = False  
155 - end  
156 - object Etiqueta5: TLabel  
157 - Left = 492  
158 - Top = 59  
159 - Width = 48  
160 - Height = 13  
161 - Caption = 'Etiqueta 5'  
162 - Font.Charset = DEFAULT_CHARSET  
163 - Font.Color = clWindowText  
164 - Font.Height = -11  
165 - Font.Name = 'MS Sans Serif'  
166 - Font.Style = []  
167 - ParentFont = False  
168 - end  
169 - object Etiqueta6: TLabel  
170 - Left = 645  
171 - Top = 59  
172 - Width = 48  
173 - Height = 13  
174 - Caption = 'Etiqueta 6'  
175 - Font.Charset = DEFAULT_CHARSET  
176 - Font.Color = clWindowText  
177 - Font.Height = -11  
178 - Font.Name = 'MS Sans Serif'  
179 - Font.Style = []  
180 - ParentFont = False  
181 - end  
182 - object Etiqueta7: TLabel  
183 - Left = 341  
184 - Top = 101  
185 - Width = 48  
186 - Height = 13  
187 - Caption = 'Etiqueta 7'  
188 - Font.Charset = DEFAULT_CHARSET  
189 - Font.Color = clWindowText  
190 - Font.Height = -11  
191 - Font.Name = 'MS Sans Serif'  
192 - Font.Style = []  
193 - ParentFont = False  
194 - end  
195 - object Etiqueta8: TLabel  
196 - Left = 492  
197 - Top = 101  
198 - Width = 48  
199 - Height = 13  
200 - Caption = 'Etiqueta 8'  
201 - Font.Charset = DEFAULT_CHARSET  
202 - Font.Color = clWindowText  
203 - Font.Height = -11  
204 - Font.Name = 'MS Sans Serif'  
205 - Font.Style = []  
206 - ParentFont = False  
207 - end  
208 - object Etiqueta9: TLabel  
209 - Left = 645  
210 - Top = 101  
211 - Width = 48  
212 - Height = 13  
213 - Caption = 'Etiqueta 9'  
214 - Font.Charset = DEFAULT_CHARSET  
215 - Font.Color = clWindowText  
216 - Font.Height = -11  
217 - Font.Name = 'MS Sans Serif'  
218 - Font.Style = []  
219 - ParentFont = False  
220 - end  
221 - object Etiqueta1a: TLabel  
222 - Left = 3  
223 - Top = 60  
224 - Width = 54  
225 - Height = 13  
226 - Caption = 'Etiqueta 1a'  
227 - Font.Charset = DEFAULT_CHARSET  
228 - Font.Color = clWindowText  
229 - Font.Height = -11  
230 - Font.Name = 'MS Sans Serif'  
231 - Font.Style = []  
232 - ParentFont = False  
233 - end  
234 - object id_unid_organizacional_nivel1: TComboBox  
235 - Left = 3  
236 - Top = 31  
237 - Width = 325  
238 - Height = 21  
239 - Hint = 'Esse '#233' o texto de ajuda da "Etiqueta 1"'  
240 - Style = csDropDownList  
241 - Font.Charset = DEFAULT_CHARSET  
242 - Font.Color = clWindowText  
243 - Font.Height = -11  
244 - Font.Name = 'MS Sans Serif'  
245 - Font.Style = []  
246 - ItemHeight = 13  
247 - ParentFont = False  
248 - ParentShowHint = False  
249 - ShowHint = True  
250 - TabOrder = 0  
251 - OnChange = id_unid_organizacional_nivel1Change  
252 - end  
253 - object id_unid_organizacional_nivel2: TComboBox  
254 - Left = 3  
255 - Top = 115  
256 - Width = 325  
257 - Height = 21  
258 - Style = csDropDownList  
259 - Font.Charset = DEFAULT_CHARSET  
260 - Font.Color = clWindowText  
261 - Font.Height = -11  
262 - Font.Name = 'MS Sans Serif'  
263 - Font.Style = []  
264 - ItemHeight = 13  
265 - ParentFont = False  
266 - ParentShowHint = False  
267 - ShowHint = True  
268 - TabOrder = 1  
269 - end  
270 - object te_localizacao_complementar: TEdit  
271 - Left = 341  
272 - Top = 31  
273 - Width = 434  
274 - Height = 21  
275 - Font.Charset = DEFAULT_CHARSET  
276 - Font.Color = clWindowText  
277 - Font.Height = -11  
278 - Font.Name = 'MS Sans Serif'  
279 - Font.Style = []  
280 - MaxLength = 100  
281 - ParentFont = False  
282 - ParentShowHint = False  
283 - ShowHint = True  
284 - TabOrder = 2  
285 - end  
286 - object te_info_patrimonio3: TEdit  
287 - Left = 645  
288 - Top = 73  
289 - Width = 130  
290 - Height = 21  
291 - Font.Charset = DEFAULT_CHARSET  
292 - Font.Color = clWindowText  
293 - Font.Height = -11  
294 - Font.Name = 'MS Sans Serif'  
295 - Font.Style = []  
296 - MaxLength = 20  
297 - ParentFont = False  
298 - ParentShowHint = False  
299 - ShowHint = True  
300 - TabOrder = 5  
301 - end  
302 - object te_info_patrimonio1: TEdit  
303 - Left = 341  
304 - Top = 73  
305 - Width = 130  
306 - Height = 21  
307 - Font.Charset = DEFAULT_CHARSET  
308 - Font.Color = clWindowText  
309 - Font.Height = -11  
310 - Font.Name = 'MS Sans Serif'  
311 - Font.Style = []  
312 - MaxLength = 20  
313 - ParentFont = False  
314 - ParentShowHint = False  
315 - ShowHint = True  
316 - TabOrder = 3  
317 - end  
318 - object te_info_patrimonio2: TEdit  
319 - Left = 492  
320 - Top = 73  
321 - Width = 130  
322 - Height = 21  
323 - Font.Charset = DEFAULT_CHARSET  
324 - Font.Color = clWindowText  
325 - Font.Height = -11  
326 - Font.Name = 'MS Sans Serif'  
327 - Font.Style = []  
328 - MaxLength = 20  
329 - ParentFont = False  
330 - ParentShowHint = False  
331 - ShowHint = True  
332 - TabOrder = 4  
333 - end  
334 - object te_info_patrimonio6: TEdit  
335 - Left = 645  
336 - Top = 115  
337 - Width = 130  
338 - Height = 21  
339 - Font.Charset = DEFAULT_CHARSET  
340 - Font.Color = clWindowText  
341 - Font.Height = -11  
342 - Font.Name = 'MS Sans Serif'  
343 - Font.Style = []  
344 - MaxLength = 20  
345 - ParentFont = False  
346 - ParentShowHint = False  
347 - ShowHint = True  
348 - TabOrder = 8  
349 - end  
350 - object te_info_patrimonio4: TEdit  
351 - Left = 341  
352 - Top = 115  
353 - Width = 130  
354 - Height = 21  
355 - Font.Charset = DEFAULT_CHARSET  
356 - Font.Color = clWindowText  
357 - Font.Height = -11  
358 - Font.Name = 'MS Sans Serif'  
359 - Font.Style = []  
360 - MaxLength = 20  
361 - ParentFont = False  
362 - ParentShowHint = False  
363 - ShowHint = True  
364 - TabOrder = 6  
365 - end  
366 - object te_info_patrimonio5: TEdit  
367 - Left = 492  
368 - Top = 115  
369 - Width = 130  
370 - Height = 21  
371 - Font.Charset = DEFAULT_CHARSET  
372 - Font.Color = clWindowText  
373 - Font.Height = -11  
374 - Font.Name = 'MS Sans Serif'  
375 - Font.Style = []  
376 - MaxLength = 20  
377 - ParentFont = False  
378 - ParentShowHint = False  
379 - ShowHint = True  
380 - TabOrder = 7  
381 - end  
382 - object id_unid_organizacional_nivel1a: TComboBox  
383 - Left = 3  
384 - Top = 73  
385 - Width = 325  
386 - Height = 21  
387 - Hint = 'Esse '#233' o texto de ajuda da "Etiqueta 1"'  
388 - Style = csDropDownList  
389 - Font.Charset = DEFAULT_CHARSET  
390 - Font.Color = clWindowText  
391 - Font.Height = -11  
392 - Font.Name = 'MS Sans Serif'  
393 - Font.Style = []  
394 - ItemHeight = 13  
395 - ParentFont = False  
396 - ParentShowHint = False  
397 - ShowHint = True  
398 - TabOrder = 9  
399 - OnChange = id_unid_organizacional_nivel1aChange  
400 - end  
401 - object Panel1: TPanel  
402 - Left = 333  
403 - Top = 15  
404 - Width = 2  
405 - Height = 125  
406 - Caption = 'Panel1'  
407 - TabOrder = 10  
408 - end  
409 - end  
410 - object Button2: TButton  
411 - Left = 290  
412 - Top = 237  
413 - Width = 212  
414 - Height = 33  
415 - Caption = 'Gravar Informa'#231#245'es Patrimoniais'  
416 - Font.Charset = DEFAULT_CHARSET  
417 - Font.Color = clWindowText  
418 - Font.Height = -11  
419 - Font.Name = 'MS Sans Serif'  
420 - Font.Style = [fsBold]  
421 - ParentFont = False  
422 - TabOrder = 2  
423 - OnClick = AtualizaPatrimonio  
424 - end  
425 -end  
col_patr/main_col_patr.pas
@@ -1,1001 +0,0 @@ @@ -1,1001 +0,0 @@
1 -(**  
2 ----------------------------------------------------------------------------------------------------------------------------------------------------------------  
3 -Copyright 2000, 2001, 2002, 2003, 2004, 2005 Dataprev - Empresa de Tecnologia e Informações da Previdência Social, Brasil  
4 -  
5 -Este arquivo é parte do programa CACIC - Configurador Automático e Coletor de Informações Computacionais  
6 -  
7 -O CACIC é um software livre; você pode redistribui-lo e/ou modifica-lo dentro dos termos da Licença Pública Geral GNU como  
8 -publicada pela Fundação do Software Livre (FSF); na versão 2 da Licença, ou (na sua opinião) qualquer versão.  
9 -  
10 -Este programa é distribuido na esperança que possa ser util, mas SEM NENHUMA GARANTIA; sem uma garantia implicita de ADEQUAÇÂO a qualquer  
11 -MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU para maiores detalhes.  
12 -  
13 -Você deve ter recebido uma cópia da Licença Pública Geral GNU, sob o título "LICENCA.txt", junto com este programa, se não, escreva para a Fundação do Software  
14 -Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA  
15 ----------------------------------------------------------------------------------------------------------------------------------------------------------------  
16 -*)  
17 -  
18 -unit main_col_patr;  
19 -  
20 -interface  
21 -  
22 -uses  
23 - IniFiles,  
24 - Windows,  
25 - Sysutils, // Deve ser colocado após o Windows acima, nunca antes  
26 - Registry,  
27 - LibXmlParser,  
28 - XML,  
29 - StdCtrls,  
30 - Controls,  
31 - Classes,  
32 - Forms,  
33 - PJVersionInfo,  
34 - DIALOGS,  
35 - ExtCtrls,  
36 - Math,  
37 - CACIC_Library;  
38 -  
39 -var  
40 - v_Dados_Patrimonio,  
41 - v_tstrCipherOpened,  
42 - v_tstrCipherOpened1 : TStrings;  
43 -  
44 -var  
45 - v_strCipherClosed,  
46 - v_strCipherOpened,  
47 - v_configs,  
48 - v_option : String;  
49 -  
50 -var  
51 - v_Debugs,  
52 - l_cs_cipher : boolean;  
53 -  
54 -var  
55 - g_oCacic : TCACIC;  
56 -  
57 -type  
58 - TFormPatrimonio = class(TForm)  
59 - GroupBox1: TGroupBox;  
60 - Label10: TLabel;  
61 - Label11: TLabel;  
62 - GroupBox2: TGroupBox;  
63 - Etiqueta1: TLabel;  
64 - Etiqueta2: TLabel;  
65 - Etiqueta3: TLabel;  
66 - id_unid_organizacional_nivel1: TComboBox;  
67 - id_unid_organizacional_nivel2: TComboBox;  
68 - te_localizacao_complementar: TEdit;  
69 - Button2: TButton;  
70 - Etiqueta4: TLabel;  
71 - Etiqueta5: TLabel;  
72 - Etiqueta6: TLabel;  
73 - Etiqueta7: TLabel;  
74 - Etiqueta8: TLabel;  
75 - Etiqueta9: TLabel;  
76 - te_info_patrimonio1: TEdit;  
77 - te_info_patrimonio2: TEdit;  
78 - te_info_patrimonio3: TEdit;  
79 - te_info_patrimonio4: TEdit;  
80 - te_info_patrimonio5: TEdit;  
81 - te_info_patrimonio6: TEdit;  
82 - Etiqueta1a: TLabel;  
83 - id_unid_organizacional_nivel1a: TComboBox;  
84 - Panel1: TPanel;  
85 - lbVersao: TLabel;  
86 -  
87 - function SetValorChaveRegEdit(Chave: String; Dado: Variant): Variant;  
88 - function GetValorChaveRegEdit(Chave: String): Variant;  
89 - function GetRootKey(strRootKey: String): HKEY;  
90 - Function RemoveCaracteresEspeciais(Texto, p_Fill : String; p_start, p_end:integer) : String;  
91 - Function CipherClose(p_DatFileName : string; p_tstrCipherOpened : TStrings) : String;  
92 - Function CipherOpen(p_DatFileName : string) : TStrings;  
93 - Function GetValorDatMemoria(p_Chave : String; p_tstrCipherOpened : TStrings) : String;  
94 - procedure FormCreate(Sender: TObject);  
95 - procedure MontaCombos;  
96 - procedure MontaInterface;  
97 - procedure FormClose(Sender: TObject; var Action: TCloseAction);  
98 - procedure id_unid_organizacional_nivel1Change(Sender: TObject);  
99 - procedure AtualizaPatrimonio(Sender: TObject);  
100 - procedure RecuperaValoresAnteriores;  
101 - procedure log_diario(strMsg : String);  
102 - procedure log_DEBUG(p_msg:string);  
103 - Procedure SetValorDatMemoria(p_Chave : string; p_Valor : String; p_tstrCipherOpened : TStrings);  
104 - function GetVersionInfo(p_File: string):string;  
105 - function VerFmt(const MS, LS: DWORD): string;  
106 - function GetFolderDate(Folder: string): TDateTime;  
107 - procedure id_unid_organizacional_nivel1aChange(Sender: TObject);  
108 - private  
109 - var_id_unid_organizacional_nivel1,  
110 - var_id_unid_organizacional_nivel1a,  
111 - var_id_unid_organizacional_nivel2,  
112 - var_id_Local,  
113 - var_te_localizacao_complementar,  
114 - var_te_info_patrimonio1,  
115 - var_te_info_patrimonio2,  
116 - var_te_info_patrimonio3,  
117 - var_te_info_patrimonio4,  
118 - var_te_info_patrimonio5,  
119 - var_te_info_patrimonio6 : String;  
120 - public  
121 - end;  
122 -  
123 -var  
124 - FormPatrimonio: TFormPatrimonio;  
125 -  
126 -implementation  
127 -  
128 -{$R *.dfm}  
129 -  
130 -  
131 -// Estruturas de dados para armazenar os itens da uon1 e uon2  
132 -type  
133 - TRegistroUON1 = record  
134 - id1 : String;  
135 - nm1 : String;  
136 - end;  
137 - TVetorUON1 = array of TRegistroUON1;  
138 -  
139 - TRegistroUON1a = record  
140 - id1 : String;  
141 - id1a : String;  
142 - nm1a : String;  
143 - id_local: String;  
144 - end;  
145 -  
146 - TVetorUON1a = array of TRegistroUON1a;  
147 -  
148 - TRegistroUON2 = record  
149 - id1a : String;  
150 - id2 : String;  
151 - nm2 : String;  
152 - id_local: String;  
153 - end;  
154 - TVetorUON2 = array of TRegistroUON2;  
155 -  
156 -var VetorUON1 : TVetorUON1;  
157 - VetorUON1a : TVetorUON1a;  
158 - VetorUON2 : TVetorUON2;  
159 -  
160 - // Esse array é usado apenas para saber a uon1a, após a filtragem pelo uon1  
161 - VetorUON1aFiltrado : array of String;  
162 -  
163 - // Esse array é usado apenas para saber a uon2, após a filtragem pelo uon1  
164 - VetorUON2Filtrado : array of String;  
165 -  
166 -function TFormPatrimonio.GetFolderDate(Folder: string): TDateTime;  
167 -var  
168 - Rec: TSearchRec;  
169 - Found: Integer;  
170 - Date: TDateTime;  
171 -begin  
172 - if Folder[Length(folder)] = '\' then  
173 - Delete(Folder, Length(folder), 1);  
174 - Result := 0;  
175 - Found := FindFirst(Folder, faDirectory, Rec);  
176 - try  
177 - if Found = 0 then  
178 - begin  
179 - Date := FileDateToDateTime(Rec.Time);  
180 - Result := Date;  
181 - end;  
182 - finally  
183 - FindClose(Rec);  
184 - end;  
185 -end;  
186 -  
187 -Function TFormPatrimonio.CipherClose(p_DatFileName : string; p_tstrCipherOpened : TStrings) : String;  
188 -var v_strCipherOpenImploded : string;  
189 - v_DatFile : TextFile;  
190 - v_cs_cipher : boolean;  
191 -begin  
192 - try  
193 - FileSetAttr (p_DatFileName,0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000  
194 - AssignFile(v_DatFile,p_DatFileName); {Associa o arquivo a uma variável do tipo TextFile}  
195 -  
196 - // Criação do arquivo .DAT  
197 - Rewrite (v_DatFile);  
198 - Append(v_DatFile);  
199 -  
200 - v_strCipherOpenImploded := g_oCacic.implode(p_tstrCipherOpened,g_oCacic.getSeparatorKey);  
201 - v_cs_cipher := l_cs_cipher;  
202 - l_cs_cipher := true;  
203 - log_DEBUG('Rotina de Fechamento do cacic2.dat ATIVANDO criptografia.');  
204 - v_strCipherClosed := g_oCacic.enCrypt(v_strCipherOpenImploded);  
205 - l_cs_cipher := v_cs_cipher;  
206 - log_DEBUG('Rotina de Fechamento do cacic2.dat RESTAURANDO estado da criptografia.');  
207 -  
208 - Writeln(v_DatFile,v_strCipherClosed); {Grava a string Texto no arquivo texto}  
209 -  
210 - CloseFile(v_DatFile);  
211 - except  
212 - end;  
213 -end;  
214 -  
215 -Function TFormPatrimonio.CipherOpen(p_DatFileName : string) : TStrings;  
216 -var v_DatFile : TextFile;  
217 - v_strCipherOpened,  
218 - v_strCipherClosed : string;  
219 - intLoop : integer;  
220 - v_cs_cipher : boolean;  
221 -begin  
222 - v_strCipherOpened := '';  
223 - if FileExists(p_DatFileName) then  
224 - begin  
225 - AssignFile(v_DatFile,p_DatFileName);  
226 - {$IOChecks off}  
227 - Reset(v_DatFile);  
228 - {$IOChecks on}  
229 - if (IOResult <> 0) then // Arquivo não existe, será recriado.  
230 - begin  
231 - Rewrite (v_DatFile);  
232 - Append(v_DatFile);  
233 - end;  
234 -  
235 - Readln(v_DatFile,v_strCipherClosed);  
236 - while not EOF(v_DatFile) do Readln(v_DatFile,v_strCipherClosed);  
237 - CloseFile(v_DatFile);  
238 - v_cs_cipher := l_cs_cipher;  
239 - l_cs_cipher := true;  
240 - log_DEBUG('Rotina de Abertura do cacic2.dat ATIVANDO criptografia.');  
241 - v_strCipherOpened:= g_oCacic.deCrypt(v_strCipherClosed);  
242 - l_cs_cipher := v_cs_cipher;  
243 - log_DEBUG('Rotina de Abertura do cacic2.dat RESTAURANDO estado da criptografia.');  
244 - end;  
245 - if (trim(v_strCipherOpened)<>'') then  
246 - Result := g_oCacic.explode(v_strCipherOpened,g_oCacic.getSeparatorKey)  
247 - else  
248 - Result := g_oCacic.explode('Configs.ID_SO' + g_oCacic.getSeparatorKey + g_oCacic.getWindowsStrId() + g_oCacic.getSeparatorKey + 'Configs.Endereco_WS' + g_oCacic.getSeparatorKey + '/cacic2/ws/',g_oCacic.getSeparatorKey);  
249 -  
250 - if Result.Count mod 2 = 0 then  
251 - Result.Add('');  
252 -  
253 - log_DEBUG('MemoryDAT aberto com sucesso!');  
254 - if v_Debugs then  
255 - for intLoop := 0 to (Result.Count-1) do  
256 - log_DEBUG('Posição ['+inttostr(intLoop)+'] do MemoryDAT: '+Result[intLoop]);  
257 -  
258 -end;  
259 -  
260 -Procedure TFormPatrimonio.SetValorDatMemoria(p_Chave : string; p_Valor : String; p_tstrCipherOpened : TStrings);  
261 -begin  
262 - log_DEBUG('Gravando Chave: "'+p_Chave+ '" => "'+p_Valor+'"');  
263 - // Exemplo: p_Chave => Configs.nu_ip_servidor : p_Valor => 10.71.0.120  
264 - if (p_tstrCipherOpened.IndexOf(p_Chave)<>-1) then  
265 - p_tstrCipherOpened[v_tstrCipherOpened.IndexOf(p_Chave)+1] := p_Valor  
266 - else  
267 - Begin  
268 - p_tstrCipherOpened.Add(p_Chave);  
269 - p_tstrCipherOpened.Add(p_Valor);  
270 - End;  
271 -end;  
272 -Function TFormPatrimonio.GetValorDatMemoria(p_Chave : String; p_tstrCipherOpened : TStrings) : String;  
273 -begin  
274 -  
275 - if (p_tstrCipherOpened.IndexOf(p_Chave)<>-1) then  
276 - Result := trim(p_tstrCipherOpened[p_tstrCipherOpened.IndexOf(p_Chave)+1])  
277 - else  
278 - Result := '';  
279 - log_DEBUG('Resgatando Chave: "'+p_Chave+ '" => "'+Result+'"');  
280 -end;  
281 -  
282 -function TFormPatrimonio.SetValorChaveRegEdit(Chave: String; Dado: Variant): Variant;  
283 -var RegEditSet: TRegistry;  
284 - RegDataType: TRegDataType;  
285 - strRootKey, strKey, strValue : String;  
286 - ListaAuxSet : TStrings;  
287 - I : Integer;  
288 -begin  
289 - ListaAuxSet := g_oCacic.explode(Chave, '\');  
290 - strRootKey := ListaAuxSet[0];  
291 - For I := 1 To ListaAuxSet.Count - 2 Do strKey := strKey + ListaAuxSet[I] + '\';  
292 - strValue := ListaAuxSet[ListaAuxSet.Count - 1];  
293 -  
294 - RegEditSet := TRegistry.Create;  
295 - try  
296 - RegEditSet.Access := KEY_WRITE;  
297 - RegEditSet.Rootkey := GetRootKey(strRootKey);  
298 -  
299 - if RegEditSet.OpenKey(strKey, True) then  
300 - Begin  
301 - RegDataType := RegEditSet.GetDataType(strValue);  
302 - if RegDataType = rdString then  
303 - begin  
304 - RegEditSet.WriteString(strValue, Dado);  
305 - end  
306 - else if RegDataType = rdExpandString then  
307 - begin  
308 - RegEditSet.WriteExpandString(strValue, Dado);  
309 - end  
310 - else if RegDataType = rdInteger then  
311 - begin  
312 - RegEditSet.WriteInteger(strValue, Dado);  
313 - end  
314 - else  
315 - begin  
316 - RegEditSet.WriteString(strValue, Dado);  
317 - end;  
318 -  
319 - end;  
320 - finally  
321 - RegEditSet.CloseKey;  
322 - end;  
323 - ListaAuxSet.Free;  
324 - RegEditSet.Free;  
325 -end;  
326 -  
327 -  
328 -function TFormPatrimonio.GetRootKey(strRootKey: String): HKEY;  
329 -begin  
330 - if Trim(strRootKey) = 'HKEY_LOCAL_MACHINE' Then Result := HKEY_LOCAL_MACHINE  
331 - else if Trim(strRootKey) = 'HKEY_CLASSES_ROOT' Then Result := HKEY_CLASSES_ROOT  
332 - else if Trim(strRootKey) = 'HKEY_CURRENT_USER' Then Result := HKEY_CURRENT_USER  
333 - else if Trim(strRootKey) = 'HKEY_USERS' Then Result := HKEY_USERS  
334 - else if Trim(strRootKey) = 'HKEY_CURRENT_CONFIG' Then Result := HKEY_CURRENT_CONFIG  
335 - else if Trim(strRootKey) = 'HKEY_DYN_DATA' Then Result := HKEY_DYN_DATA;  
336 -end;  
337 -  
338 -function TformPatrimonio.VerFmt(const MS, LS: DWORD): string;  
339 - // Format the version number from the given DWORDs containing the info  
340 -begin  
341 - Result := Format('%d.%d.%d.%d',  
342 - [HiWord(MS), LoWord(MS), HiWord(LS), LoWord(LS)])  
343 -end;  
344 -  
345 -function TformPatrimonio.GetVersionInfo(p_File: string):string;  
346 -var PJVersionInfo1: TPJVersionInfo;  
347 -begin  
348 - PJVersionInfo1 := TPJVersionInfo.Create(nil);  
349 - PJVersionInfo1.FileName := PChar(p_File);  
350 - Result := VerFmt(PJVersionInfo1.FixedFileInfo.dwFileVersionMS, PJVersionInfo1.FixedFileInfo.dwFileVersionLS);  
351 - PJVersionInfo1.Free;  
352 -end;  
353 -  
354 -procedure TformPatrimonio.log_DEBUG(p_msg:string);  
355 -Begin  
356 - if v_Debugs then log_diario('(v.'+getVersionInfo(ParamStr(0))+') DEBUG - '+p_msg);  
357 -End;  
358 -  
359 -  
360 -procedure TformPatrimonio.log_diario(strMsg : String);  
361 -var  
362 - HistoricoLog : TextFile;  
363 - strDataArqLocal, strDataAtual : string;  
364 -begin  
365 - try  
366 - FileSetAttr (g_oCacic.getCacicPath + 'cacic2.log',0); // Retira os atributos do arquivo para evitar o erro FILE ACCESS DENIED em máquinas 2000  
367 - AssignFile(HistoricoLog,g_oCacic.getCacicPath + 'cacic2.log'); {Associa o arquivo a uma variável do tipo TextFile}  
368 - {$IOChecks off}  
369 - Reset(HistoricoLog); {Abre o arquivo texto}  
370 - {$IOChecks on}  
371 - if (IOResult <> 0) then // Arquivo não existe, será recriado.  
372 - begin  
373 - Rewrite (HistoricoLog);  
374 - Append(HistoricoLog);  
375 - Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now) + '======================> Iniciando o Log do CACIC <=======================');  
376 - end;  
377 - DateTimeToString(strDataArqLocal, 'yyyymmdd', FileDateToDateTime(Fileage(g_oCacic.getCacicPath + 'cacic2.log')));  
378 - DateTimeToString(strDataAtual , 'yyyymmdd', Date);  
379 - if (strDataAtual <> strDataArqLocal) then // Se o arquivo INI não é da data atual...  
380 - begin  
381 - Rewrite (HistoricoLog); //Cria/Recria o arquivo  
382 - Append(HistoricoLog);  
383 - Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now) + '======================> Iniciando o Log do CACIC <=======================');  
384 - end;  
385 - Append(HistoricoLog);  
386 - Writeln(HistoricoLog,FormatDateTime('dd/mm hh:nn:ss : ', Now)+ '[Coletor PATR] '+strMsg); {Grava a string Texto no arquivo texto}  
387 - CloseFile(HistoricoLog); {Fecha o arquivo texto}  
388 - except  
389 - log_diario('Erro na gravação do log!');  
390 - end;  
391 -end;  
392 -  
393 -Function RetornaValorVetorUON1(id1 : string) : String;  
394 -var I : Integer;  
395 -begin  
396 - For I := 0 to (Length(VetorUON1)-1) Do  
397 - If (VetorUON1[I].id1 = id1) Then Result := VetorUON1[I].nm1;  
398 -end;  
399 -  
400 -Function RetornaValorVetorUON1a(id1a : string) : String;  
401 -var I : Integer;  
402 -begin  
403 - For I := 0 to (Length(VetorUON1a)-1) Do  
404 - If (VetorUON1a[I].id1a = id1a) Then Result := VetorUON1a[I].nm1a;  
405 -end;  
406 -Function RetornaValorVetorUON2(id2, idLocal : string) : String;  
407 -var I : Integer;  
408 -begin  
409 - For I := 0 to (Length(VetorUON2)-1) Do  
410 - If (VetorUON2[I].id2 = id2) and  
411 - (VetorUON2[I].id_local = idLocal) Then Result := VetorUON2[I].nm2;  
412 -end;  
413 -  
414 -  
415 -procedure TFormPatrimonio.RecuperaValoresAnteriores;  
416 -begin  
417 - Etiqueta1.Caption := g_oCacic.deCrypt(XML.XML_RetornaValor('te_etiqueta1', v_configs));  
418 - Etiqueta1a.Caption := g_oCacic.deCrypt(XML.XML_RetornaValor('te_etiqueta1a', v_configs));  
419 -  
420 - var_id_unid_organizacional_nivel1 := GetValorDatMemoria('Patrimonio.id_unid_organizacional_nivel1',v_tstrCipherOpened);  
421 - if (var_id_unid_organizacional_nivel1='') then var_id_unid_organizacional_nivel1 := g_oCacic.deCrypt(XML.XML_RetornaValor('ID_UON1', v_configs));  
422 -  
423 - var_id_unid_organizacional_nivel1a := GetValorDatMemoria('Patrimonio.id_unid_organizacional_nivel1a',v_tstrCipherOpened);  
424 - if (var_id_unid_organizacional_nivel1a='') then var_id_unid_organizacional_nivel1a := g_oCacic.deCrypt(XML.XML_RetornaValor('ID_UON1a', v_configs));  
425 -  
426 - var_id_unid_organizacional_nivel2 := GetValorDatMemoria('Patrimonio.id_unid_organizacional_nivel2',v_tstrCipherOpened);  
427 - if (var_id_unid_organizacional_nivel2='') then var_id_unid_organizacional_nivel2 := g_oCacic.deCrypt(XML.XML_RetornaValor('ID_UON2', v_configs));  
428 -  
429 - var_te_localizacao_complementar := GetValorDatMemoria('Patrimonio.te_localizacao_complementar',v_tstrCipherOpened);  
430 - if (var_te_localizacao_complementar='') then var_te_localizacao_complementar := g_oCacic.deCrypt(XML.XML_RetornaValor('TE_LOC_COMPL', v_configs));  
431 -  
432 - // Tentarei buscar informação gravada no Registry  
433 - var_te_info_patrimonio1 := GetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SOFTWARE\Dataprev\Patrimonio\te_info_patrimonio1');  
434 - if (var_te_info_patrimonio1='') then  
435 - Begin  
436 - var_te_info_patrimonio1 := GetValorDatMemoria('Patrimonio.te_info_patrimonio1',v_tstrCipherOpened);  
437 - End;  
438 - if (var_te_info_patrimonio1='') then var_te_info_patrimonio1 := g_oCacic.deCrypt(XML.XML_RetornaValor('TE_INFO1', v_configs));  
439 -  
440 - var_te_info_patrimonio2 := GetValorDatMemoria('Patrimonio.te_info_patrimonio2',v_tstrCipherOpened);  
441 - if (var_te_info_patrimonio2='') then var_te_info_patrimonio2 := g_oCacic.deCrypt(XML.XML_RetornaValor('TE_INFO2', v_configs));  
442 -  
443 - var_te_info_patrimonio3 := GetValorDatMemoria('Patrimonio.te_info_patrimonio3',v_tstrCipherOpened);  
444 - if (var_te_info_patrimonio3='') then var_te_info_patrimonio3 := g_oCacic.deCrypt(XML.XML_RetornaValor('TE_INFO3', v_configs));  
445 -  
446 - // Tentarei buscar informação gravada no Registry  
447 - var_te_info_patrimonio4 := GetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SOFTWARE\Dataprev\Patrimonio\te_info_patrimonio4');  
448 - if (var_te_info_patrimonio4='') then  
449 - Begin  
450 - var_te_info_patrimonio4 := GetValorDatMemoria('Patrimonio.te_info_patrimonio4',v_tstrCipherOpened);  
451 - End;  
452 - if (var_te_info_patrimonio4='') then var_te_info_patrimonio4 := g_oCacic.deCrypt(XML.XML_RetornaValor('TE_INFO4', v_configs));  
453 -  
454 - var_te_info_patrimonio5 := GetValorDatMemoria('Patrimonio.te_info_patrimonio5',v_tstrCipherOpened);  
455 - if (var_te_info_patrimonio5='') then var_te_info_patrimonio5 := g_oCacic.deCrypt(XML.XML_RetornaValor('TE_INFO5', v_configs));  
456 -  
457 - var_te_info_patrimonio6 := GetValorDatMemoria('Patrimonio.te_info_patrimonio6',v_tstrCipherOpened);  
458 - if (var_te_info_patrimonio6='') then var_te_info_patrimonio6 := g_oCacic.deCrypt(XML.XML_RetornaValor('TE_INFO6', v_configs));  
459 -  
460 - Try  
461 - id_unid_organizacional_nivel1.ItemIndex := id_unid_organizacional_nivel1.Items.IndexOf(RetornaValorVetorUON1(var_id_unid_organizacional_nivel1));  
462 - id_unid_organizacional_nivel1Change(Nil); // Para filtrar os valores do combo2 de acordo com o valor selecionado no combo1  
463 -  
464 - Except  
465 - end;  
466 -  
467 - Try  
468 - id_unid_organizacional_nivel1a.ItemIndex := id_unid_organizacional_nivel1a.Items.IndexOf(RetornaValorVetorUON1a(var_id_unid_organizacional_nivel1a));  
469 - id_unid_organizacional_nivel1aChange(Nil); // Para filtrar os valores do combo3 de acordo com o valor selecionado no combo2  
470 - Except  
471 - End;  
472 -  
473 - Try  
474 - id_unid_organizacional_nivel2.ItemIndex := id_unid_organizacional_nivel2.Items.IndexOf(RetornaValorVetorUON2(var_id_unid_organizacional_nivel2,var_id_Local));  
475 - Except  
476 - end;  
477 -  
478 -  
479 - te_localizacao_complementar.Text := var_te_localizacao_complementar;  
480 - te_info_patrimonio1.Text := var_te_info_patrimonio1;  
481 - te_info_patrimonio2.Text := var_te_info_patrimonio2;  
482 - te_info_patrimonio3.Text := var_te_info_patrimonio3;  
483 - te_info_patrimonio4.Text := var_te_info_patrimonio4;  
484 - te_info_patrimonio5.Text := var_te_info_patrimonio5;  
485 - te_info_patrimonio6.Text := var_te_info_patrimonio6;  
486 -end;  
487 -  
488 -  
489 -  
490 -procedure TFormPatrimonio.MontaCombos;  
491 -var Parser : TXmlParser;  
492 - i : integer;  
493 - v_Tag : boolean;  
494 - strAux,  
495 - strAux1,  
496 - strTagName,  
497 - strItemName : string;  
498 -begin  
499 - Parser := TXmlParser.Create;  
500 - Parser.Normalize := True;  
501 - Parser.LoadFromBuffer(PAnsiChar(v_Configs));  
502 - log_DEBUG('v_Configs: '+v_Configs);  
503 - Parser.StartScan;  
504 - i := -1;  
505 - strItemName := '';  
506 - strTagName := '';  
507 - While Parser.Scan DO  
508 - Begin  
509 - strItemName := UpperCase(Parser.CurName);  
510 - if (Parser.CurPartType = ptStartTag) and (strItemName = 'IT1') Then  
511 - Begin  
512 - i := i + 1;  
513 - SetLength(VetorUON1, i + 1); // Aumento o tamanho da matriz dinamicamente de acordo com o número de itens recebidos.  
514 - strTagName := 'IT1';  
515 - end  
516 - else if (Parser.CurPartType = ptEndTag) and (strItemName = 'IT1') then  
517 - strTagName := ''  
518 - else if (Parser.CurPartType in [ptContent, ptCData]) and (strTagName='IT1')Then  
519 - Begin  
520 - strAux1 := g_oCacic.deCrypt(Parser.CurContent);  
521 - if (strItemName = 'ID1') then  
522 - Begin  
523 - VetorUON1[i].id1 := strAux1;  
524 - log_DEBUG('Gravei VetorUON1.id1: "'+strAux1+'"');  
525 - End  
526 - else if (strItemName = 'NM1') then  
527 - Begin  
528 - VetorUON1[i].nm1 := strAux1;  
529 - log_DEBUG('Gravei VetorUON1.nm1: "'+strAux1+'"');  
530 - End;  
531 - End;  
532 - End;  
533 -  
534 - // Código para montar o combo 2  
535 - Parser.StartScan;  
536 - strTagName := '';  
537 - strAux1 := '';  
538 - i := -1;  
539 - While Parser.Scan DO  
540 - Begin  
541 - strItemName := UpperCase(Parser.CurName);  
542 - if (Parser.CurPartType = ptStartTag) and (strItemName = 'IT1A') Then  
543 - Begin  
544 - i := i + 1;  
545 - SetLength(VetorUON1a, i + 1); // Aumento o tamanho da matriz dinamicamente de acordo com o número de itens recebidos.  
546 - strTagName := 'IT1A';  
547 - end  
548 - else if (Parser.CurPartType = ptEndTag) and (strItemName = 'IT1A') then  
549 - strTagName := ''  
550 - else if (Parser.CurPartType in [ptContent, ptCData]) and (strTagName='IT1A')Then  
551 - Begin  
552 - strAux1 := g_oCacic.deCrypt(Parser.CurContent);  
553 - if (strItemName = 'ID1') then  
554 - Begin  
555 - VetorUON1a[i].id1 := strAux1;  
556 - log_DEBUG('Gravei VetorUON1a.id1: "'+strAux1+'"');  
557 - End  
558 - else if (strItemName = 'SG_LOC') then  
559 - Begin  
560 - strAux := ' ('+strAux1 + ')';  
561 - End  
562 - else if (strItemName = 'ID1A') then  
563 - Begin  
564 - VetorUON1a[i].id1a := strAux1;  
565 - log_DEBUG('Gravei VetorUON1a.id1a: "'+strAux1+'"');  
566 - End  
567 - else if (strItemName = 'NM1A') then  
568 - Begin  
569 - VetorUON1a[i].nm1a := strAux1+strAux;  
570 - log_DEBUG('Gravei VetorUON1a.nm1a: "'+strAux1+strAux+'"');  
571 - End  
572 - else if (strItemName = 'ID_LOCAL') then  
573 - Begin  
574 - VetorUON1a[i].id_local := strAux1;  
575 - log_DEBUG('Gravei VetorUON1a.id_local: "'+strAux1+'"');  
576 - End;  
577 -  
578 - End;  
579 - end;  
580 -  
581 - // Código para montar o combo 3  
582 - Parser.StartScan;  
583 - strTagName := '';  
584 - i := -1;  
585 - While Parser.Scan DO  
586 - Begin  
587 - strItemName := UpperCase(Parser.CurName);  
588 - if (Parser.CurPartType = ptStartTag) and (strItemName = 'IT2') Then  
589 - Begin  
590 - i := i + 1;  
591 - SetLength(VetorUON2, i + 1); // Aumento o tamanho da matriz dinamicamente de acordo com o número de itens recebidos.  
592 - strTagName := 'IT2';  
593 - end  
594 - else if (Parser.CurPartType = ptEndTag) and (strItemName = 'IT2') then  
595 - strTagName := ''  
596 - else if (Parser.CurPartType in [ptContent, ptCData]) and (strTagName='IT2')Then  
597 - Begin  
598 - strAux1 := g_oCacic.deCrypt(Parser.CurContent);  
599 - if (strItemName = 'ID1A') then  
600 - Begin  
601 - VetorUON2[i].id1a := strAux1;  
602 - log_DEBUG('Gravei VetorUON2.id1a: "'+strAux1+'"');  
603 - End  
604 - else if (strItemName = 'ID2') then  
605 - Begin  
606 - VetorUON2[i].id2 := strAux1;  
607 - log_DEBUG('Gravei VetorUON2.id2: "'+strAux1+'"');  
608 - End  
609 - else if (strItemName = 'NM2') then  
610 - Begin  
611 - VetorUON2[i].nm2 := strAux1;  
612 - log_DEBUG('Gravei VetorUON2.nm2: "'+strAux1+'"');  
613 - End  
614 - else if (strItemName = 'ID_LOCAL') then  
615 - Begin  
616 - VetorUON2[i].id_local := strAux1;  
617 - log_DEBUG('Gravei VetorUON2.id_local: "'+strAux1+'"');  
618 - End;  
619 -  
620 - End;  
621 - end;  
622 - Parser.Free;  
623 - // Como os itens do combo1 nunca mudam durante a execução do programa (ao contrario dos combo2 e 3), posso colocar o seu preenchimento aqui mesmo.  
624 - id_unid_organizacional_nivel1.Items.Clear;  
625 - For i := 0 to Length(VetorUON1) - 1 Do  
626 - id_unid_organizacional_nivel1.Items.Add(VetorUON1[i].nm1);  
627 -  
628 -end;  
629 -  
630 -  
631 -procedure TFormPatrimonio.id_unid_organizacional_nivel1Change(Sender: TObject);  
632 -var i, j: Word;  
633 - strAux,  
634 - strIdUON1 : String;  
635 -begin  
636 - // Filtro os itens do combo2, de acordo com o item selecionado no combo1  
637 - strIdUON1 := VetorUON1[id_unid_organizacional_nivel1.ItemIndex].id1;  
638 - id_unid_organizacional_nivel1a.Items.Clear;  
639 - id_unid_organizacional_nivel2.Items.Clear;  
640 - id_unid_organizacional_nivel1a.Enabled := false;  
641 - id_unid_organizacional_nivel2.Enabled := false;  
642 - SetLength(VetorUON1aFiltrado, 0);  
643 -  
644 - For i := 0 to Length(VetorUON1a) - 1 Do  
645 - Begin  
646 - Try  
647 - if VetorUON1a[i].id1 = strIdUON1 then  
648 - Begin  
649 - id_unid_organizacional_nivel1a.Items.Add(VetorUON1a[i].nm1a);  
650 - j := Length(VetorUON1aFiltrado);  
651 - SetLength(VetorUON1aFiltrado, j + 1);  
652 - VetorUON1aFiltrado[j] := VetorUON1a[i].id1a;  
653 - end;  
654 - Except  
655 - End;  
656 - end;  
657 - if (id_unid_organizacional_nivel1a.Items.Count > 0) then  
658 - Begin  
659 - id_unid_organizacional_nivel1a.Enabled := true;  
660 - id_unid_organizacional_nivel1a.ItemIndex := 0;  
661 - id_unid_organizacional_nivel1aChange(nil);  
662 - End;  
663 -  
664 -end;  
665 -procedure TFormPatrimonio.id_unid_organizacional_nivel1aChange(  
666 - Sender: TObject);  
667 -var i, j: Word;  
668 - strIdUON1a,  
669 - strIdLocal : String;  
670 - intAux : integer;  
671 -begin  
672 - // Filtro os itens do combo2, de acordo com o item selecionado no combo1  
673 - intAux := IfThen(id_unid_organizacional_nivel1a.Items.Count > 1,id_unid_organizacional_nivel1a.ItemIndex+1,0);  
674 - strIdUON1a := VetorUON1a[intAux].id1a;  
675 - strIdLocal := VetorUON1a[intAux].id_local;  
676 - id_unid_organizacional_nivel2.Items.Clear;  
677 - id_unid_organizacional_nivel2.Enabled := false;  
678 - SetLength(VetorUON2Filtrado, 0);  
679 -  
680 - For i := 0 to Length(VetorUON2) - 1 Do  
681 - Begin  
682 - Try  
683 - if (VetorUON2[i].id1a = strIdUON1a) and  
684 - (VetorUON2[i].id_local = strIdLocal) then  
685 - Begin  
686 - id_unid_organizacional_nivel2.Items.Add(VetorUON2[i].nm2);  
687 - j := Length(VetorUON2Filtrado);  
688 - SetLength(VetorUON2Filtrado, j + 1);  
689 - VetorUON2Filtrado[j] := VetorUON2[i].id2 + '#' + VetorUON2[i].id_local;  
690 - end;  
691 - Except  
692 - End;  
693 - end;  
694 - if (id_unid_organizacional_nivel2.Items.Count > 0) then  
695 - Begin  
696 - id_unid_organizacional_nivel2.Enabled := true;  
697 - id_unid_organizacional_nivel2.ItemIndex := 0;  
698 - End;  
699 -end;  
700 -  
701 -procedure TFormPatrimonio.AtualizaPatrimonio(Sender: TObject);  
702 -var strIdUON1,  
703 - strIdUON1a,  
704 - strIdUON2,  
705 - strIdLocal,  
706 - strRetorno : String;  
707 - tstrAux : TStrings;  
708 -begin  
709 - tstrAux := TStrings.Create;  
710 - tstrAux := g_oCacic.explode(VetorUON2Filtrado[id_unid_organizacional_nivel2.ItemIndex],'#');  
711 - Try  
712 - strIdUON1 := VetorUON1[id_unid_organizacional_nivel1.ItemIndex].id1;  
713 - strIdUON1a := VetorUON1aFiltrado[id_unid_organizacional_nivel1a.ItemIndex];  
714 - strIdUON2 := tstrAux[0];  
715 - strIdLocal := tstrAux[1];  
716 - Except  
717 - end;  
718 - tstrAux.Free;  
719 -  
720 - SetValorDatMemoria('Col_Patr.Fim', FormatDateTime('hh:nn:ss', Now), v_tstrCipherOpened1);  
721 - if (strIdUON1 <> var_id_unid_organizacional_nivel1) or  
722 - (strIdUON1a <> var_id_unid_organizacional_nivel1a) or  
723 - (strIdUON2 <> var_id_unid_organizacional_nivel2) or  
724 - (te_localizacao_complementar.Text <> var_te_localizacao_complementar) or  
725 - (te_info_patrimonio1.Text <> var_te_info_patrimonio1) or  
726 - (te_info_patrimonio2.Text <> var_te_info_patrimonio2) or  
727 - (te_info_patrimonio3.Text <> var_te_info_patrimonio3) or  
728 - (te_info_patrimonio4.Text <> var_te_info_patrimonio4) or  
729 - (te_info_patrimonio5.Text <> var_te_info_patrimonio5) or  
730 - (te_info_patrimonio6.Text <> var_te_info_patrimonio6) then  
731 - begin  
732 - //Envio via rede para ao Agente Gerente, para gravação no BD.  
733 - SetValorDatMemoria('Col_Patr.id_unid_organizacional_nivel1' , strIdUON1, v_tstrCipherOpened1);  
734 - SetValorDatMemoria('Col_Patr.id_unid_organizacional_nivel1a', strIdUON1a, v_tstrCipherOpened1);  
735 - SetValorDatMemoria('Col_Patr.id_unid_organizacional_nivel2' , strIdUON2, v_tstrCipherOpened1);  
736 - SetValorDatMemoria('Col_Patr.te_localizacao_complementar' , te_localizacao_complementar.Text, v_tstrCipherOpened1);  
737 - SetValorDatMemoria('Col_Patr.te_info_patrimonio1' , te_info_patrimonio1.Text, v_tstrCipherOpened1);  
738 - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SOFTWARE\Dataprev\Patrimonio\te_info_patrimonio1', te_info_patrimonio1.Text);  
739 - SetValorDatMemoria('Col_Patr.te_info_patrimonio2' , te_info_patrimonio2.Text, v_tstrCipherOpened1);  
740 - SetValorDatMemoria('Col_Patr.te_info_patrimonio3' , te_info_patrimonio3.Text, v_tstrCipherOpened1);  
741 - SetValorDatMemoria('Col_Patr.te_info_patrimonio4' , te_info_patrimonio4.Text, v_tstrCipherOpened1);  
742 - SetValorChaveRegEdit('HKEY_LOCAL_MACHINE\SOFTWARE\Dataprev\Patrimonio\te_info_patrimonio4', te_info_patrimonio4.Text);  
743 - SetValorDatMemoria('Col_Patr.te_info_patrimonio5' , te_info_patrimonio5.Text, v_tstrCipherOpened1);  
744 - SetValorDatMemoria('Col_Patr.te_info_patrimonio6' , te_info_patrimonio6.Text, v_tstrCipherOpened1);  
745 - CipherClose(g_oCacic.getCacicPath + 'temp\col_patr.dat', v_tstrCipherOpened1);  
746 - end  
747 - else  
748 - Begin  
749 - SetValorDatMemoria('Col_Patr.nada', 'nada', v_tstrCipherOpened1);  
750 - CipherClose(g_oCacic.getCacicPath + 'temp\col_patr.dat', v_tstrCipherOpened1);  
751 - End;  
752 - Application.Terminate;  
753 -end;  
754 -  
755 -procedure TFormPatrimonio.MontaInterface;  
756 -Begin  
757 - // Se houve alteração na configuração da interface, atualizo os dados no registro e depois monto a interface.  
758 - // Caso, contrário, pego direto do registro.  
759 -  
760 - Etiqueta1.Caption := g_oCacic.deCrypt(XML.XML_RetornaValor('te_etiqueta1', v_configs));  
761 - id_unid_organizacional_nivel1.Hint := g_oCacic.deCrypt(XML.XML_RetornaValor('te_help_etiqueta1', v_configs));  
762 -  
763 - Etiqueta1a.Caption := g_oCacic.deCrypt(XML.XML_RetornaValor('te_etiqueta1a', v_configs));  
764 - id_unid_organizacional_nivel1a.Hint := g_oCacic.deCrypt(XML.XML_RetornaValor('te_help_etiqueta1a', v_configs));  
765 -  
766 - Etiqueta2.Caption := g_oCacic.deCrypt(XML.XML_RetornaValor('te_etiqueta2', v_configs));  
767 - id_unid_organizacional_nivel2.Hint := g_oCacic.deCrypt(XML.XML_RetornaValor('te_help_etiqueta2', v_configs));  
768 -  
769 - Etiqueta3.Caption := g_oCacic.deCrypt(XML.XML_RetornaValor('te_etiqueta3', v_configs));  
770 -  
771 - if (g_oCacic.deCrypt(XML.XML_RetornaValor('in_exibir_etiqueta4', v_configs)) = 'S') then  
772 - begin  
773 - Etiqueta4.Caption := g_oCacic.deCrypt(XML.XML_RetornaValor('te_etiqueta4', v_configs));  
774 - te_info_patrimonio1.Hint := g_oCacic.deCrypt(XML.XML_RetornaValor('te_help_etiqueta4', v_configs));  
775 - te_info_patrimonio1.visible := True;  
776 - end  
777 - else begin  
778 - Etiqueta4.Visible := False;  
779 - te_info_patrimonio1.visible := False;  
780 -  
781 - end;  
782 -  
783 - if (g_oCacic.deCrypt(XML.XML_RetornaValor('in_exibir_etiqueta5', v_configs)) = 'S') then  
784 - begin  
785 - Etiqueta5.Caption := g_oCacic.deCrypt(XML.XML_RetornaValor('te_etiqueta5', v_configs));  
786 - te_info_patrimonio2.Hint := g_oCacic.deCrypt(XML.XML_RetornaValor('te_help_etiqueta5', v_configs));  
787 - te_info_patrimonio2.visible := True;  
788 - end  
789 - else begin  
790 - Etiqueta5.Visible := False;  
791 - te_info_patrimonio2.visible := False;  
792 - end;  
793 -  
794 - if (g_oCacic.deCrypt(XML.XML_RetornaValor('in_exibir_etiqueta6', v_configs)) = 'S') then  
795 - begin  
796 - Etiqueta6.Caption := g_oCacic.deCrypt(XML.XML_RetornaValor('te_etiqueta6', v_configs));  
797 - te_info_patrimonio3.Hint := g_oCacic.deCrypt(XML.XML_RetornaValor('te_help_etiqueta6', v_configs));  
798 - te_info_patrimonio3.visible := True;  
799 - end  
800 - else begin  
801 - Etiqueta6.Visible := False;  
802 - te_info_patrimonio3.visible := False;  
803 - end;  
804 -  
805 - if (g_oCacic.deCrypt(XML.XML_RetornaValor('in_exibir_etiqueta7', v_configs)) = 'S') then  
806 - begin  
807 - Etiqueta7.Caption := g_oCacic.deCrypt(XML.XML_RetornaValor('te_etiqueta7', v_configs));  
808 - te_info_patrimonio4.Hint := g_oCacic.deCrypt(XML.XML_RetornaValor('te_help_etiqueta7', v_configs));  
809 - te_info_patrimonio4.visible := True;  
810 - end else  
811 - begin  
812 - Etiqueta7.Visible := False;  
813 - te_info_patrimonio4.visible := False;  
814 - end;  
815 -  
816 - if (g_oCacic.deCrypt(XML.XML_RetornaValor('in_exibir_etiqueta8', v_configs)) = 'S') then  
817 - begin  
818 - Etiqueta8.Caption := g_oCacic.deCrypt(XML.XML_RetornaValor('te_etiqueta8', v_configs));  
819 - te_info_patrimonio5.Hint := g_oCacic.deCrypt(XML.XML_RetornaValor('te_help_etiqueta8', v_configs));  
820 - te_info_patrimonio5.visible := True;  
821 - end else  
822 - begin  
823 - Etiqueta8.Visible := False;  
824 - te_info_patrimonio5.visible := False;  
825 - end;  
826 -  
827 - if (g_oCacic.deCrypt(XML.XML_RetornaValor('in_exibir_etiqueta9', v_configs)) = 'S') then  
828 - begin  
829 - Etiqueta9.Caption := g_oCacic.deCrypt(XML.XML_RetornaValor('te_etiqueta9', v_configs));  
830 - te_info_patrimonio6.Hint := g_oCacic.deCrypt(XML.XML_RetornaValor('te_help_etiqueta9', v_configs));  
831 - te_info_patrimonio6.visible := True;  
832 - end  
833 - else begin  
834 - Etiqueta9.Visible := False;  
835 - te_info_patrimonio6.visible := False;  
836 - end;  
837 -end;  
838 -  
839 -procedure TFormPatrimonio.FormClose(Sender: TObject; var Action: TCloseAction);  
840 -begin  
841 - SetValorDatMemoria('Col_Patr.nada', 'nada', v_tstrCipherOpened1);  
842 - CipherClose(g_oCacic.getCacicPath + 'temp\col_patr.dat', v_tstrCipherOpened1);  
843 - Application.Terminate;  
844 -end;  
845 -// Função adaptada de http://www.latiumsoftware.com/en/delphi/00004.php  
846 -//Para buscar do RegEdit...  
847 -function TFormPatrimonio.GetValorChaveRegEdit(Chave: String): Variant;  
848 -var RegEditGet: TRegistry;  
849 - RegDataType: TRegDataType;  
850 - strRootKey, strKey, strValue, s: String;  
851 - ListaAuxGet : TStrings;  
852 - DataSize, Len, I : Integer;  
853 -begin  
854 - try  
855 - Result := '';  
856 - ListaAuxGet := g_oCacic.explode(Chave, '\');  
857 -  
858 - strRootKey := ListaAuxGet[0];  
859 - For I := 1 To ListaAuxGet.Count - 2 Do strKey := strKey + ListaAuxGet[I] + '\';  
860 - strValue := ListaAuxGet[ListaAuxGet.Count - 1];  
861 - if (strValue = '(Padrão)') then strValue := ''; //Para os casos de se querer buscar o valor default (Padrão)  
862 - RegEditGet := TRegistry.Create;  
863 -  
864 - RegEditGet.Access := KEY_READ;  
865 - RegEditGet.Rootkey := GetRootKey(strRootKey);  
866 - if RegEditGet.OpenKeyReadOnly(strKey) then //teste  
867 - Begin  
868 - RegDataType := RegEditGet.GetDataType(strValue);  
869 - if (RegDataType = rdString) or (RegDataType = rdExpandString) then Result := RegEditGet.ReadString(strValue)  
870 - else if RegDataType = rdInteger then Result := RegEditGet.ReadInteger(strValue)  
871 - else if (RegDataType = rdBinary) or (RegDataType = rdUnknown)  
872 - then  
873 - begin  
874 - DataSize := RegEditGet.GetDataSize(strValue);  
875 - if DataSize = -1 then exit;  
876 - SetLength(s, DataSize);  
877 - Len := RegEditGet.ReadBinaryData(strValue, PChar(s)^, DataSize);  
878 - if Len <> DataSize then exit;  
879 - Result := trim(RemoveCaracteresEspeciais(s,' ',32,126));  
880 - end  
881 - end;  
882 - finally  
883 - RegEditGet.CloseKey;  
884 - RegEditGet.Free;  
885 - ListaAuxGet.Free;  
886 -  
887 - end;  
888 -end;  
889 -  
890 -Function TFormPatrimonio.RemoveCaracteresEspeciais(Texto, p_Fill : String; p_start, p_end:integer) : String;  
891 -var I : Integer;  
892 - strAux : String;  
893 -Begin  
894 - strAux := '';  
895 - if (Length(trim(Texto))>0) then  
896 - For I := 0 To Length(Texto) Do  
897 - if ord(Texto[I]) in [p_start..p_end] Then  
898 - strAux := strAux + Texto[I]  
899 - else  
900 - strAux := strAux + p_Fill;  
901 - Result := strAux;  
902 -end;  
903 -  
904 -procedure TFormPatrimonio.FormCreate(Sender: TObject);  
905 -var boolColeta : boolean;  
906 - tstrTripa1 : TStrings;  
907 - i,intAux : integer;  
908 - v_Aux,  
909 - strAux : String;  
910 -Begin  
911 - g_oCacic := TCACIC.Create();  
912 -  
913 - g_oCacic.setBoolCipher(true);  
914 -  
915 - if (ParamCount>0) then  
916 - Begin  
917 - FormPatrimonio.lbVersao.Caption := 'Versão: ' + GetVersionInfo(ParamStr(0));  
918 - Begin  
919 - strAux := '';  
920 - For intAux := 1 to ParamCount do  
921 - Begin  
922 - if LowerCase(Copy(ParamStr(intAux),1,11)) = '/cacicpath=' then  
923 - begin  
924 - strAux := Trim(Copy(ParamStr(intAux),12,Length((ParamStr(intAux)))));  
925 - log_DEBUG('Parâmetro /CacicPath recebido com valor="'+strAux+'"');  
926 - end;  
927 - end;  
928 -  
929 - if (strAux <> '') then  
930 - Begin  
931 - g_oCacic.setCacicPath(strAux);  
932 - v_Debugs := false;  
933 - if DirectoryExists(g_oCacic.getCacicPath + 'Temp\Debugs') then  
934 - Begin  
935 - if (FormatDateTime('ddmmyyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs')) = FormatDateTime('ddmmyyyy', date)) then  
936 - Begin  
937 - v_Debugs := true;  
938 - log_DEBUG('Pasta "' + g_oCacic.getCacicPath + 'Temp\Debugs" com data '+FormatDateTime('dd-mm-yyyy', GetFolderDate(g_oCacic.getCacicPath + 'Temp\Debugs'))+' encontrada. DEBUG ativado.');  
939 - End;  
940 - End;  
941 -  
942 - v_tstrCipherOpened := TStrings.Create;  
943 - v_tstrCipherOpened := CipherOpen(g_oCacic.getCacicPath + g_oCacic.getDatFileName);  
944 -  
945 - v_tstrCipherOpened1 := TStrings.Create;  
946 - v_tstrCipherOpened1 := CipherOpen(g_oCacic.getCacicPath + 'temp\col_patr.dat');  
947 -  
948 - // Os valores possíveis serão 0-DESLIGADO 1-LIGADO 2-ESPERA PARA LIGAR (Será transformado em "1") 3-Ainda se comunicará com o Gerente WEB  
949 - l_cs_cipher := false;  
950 - v_Aux := GetValorDatMemoria('Configs.CS_CIPHER', v_tstrCipherOpened);  
951 - if (v_Aux='1')then  
952 - Begin  
953 - l_cs_cipher := true;  
954 - End;  
955 -  
956 - Try  
957 - boolColeta := false;  
958 - if (GetValorDatMemoria('Patrimonio.in_alteracao_fisica',v_tstrCipherOpened)= 'S') then  
959 - Begin  
960 - // Solicita o cadastramento de informações de patrimõnio caso seja detectado remanejamento para uma nova rede.  
961 - MessageDlg('Atenção: foi identificada uma alteração na localização física deste computador. Por favor, confirme as informações que serão apresentadas na tela que será exibida a seguir.', mtInformation, [mbOk], 0);  
962 - boolColeta := true;  
963 - End  
964 - Else if (GetValorDatMemoria('Patrimonio.in_renovacao_informacoes',v_tstrCipherOpened)= 'S') and (v_option='system') then  
965 - Begin  
966 - // Solicita o cadastramento de informações de patrimõnio caso tenha completado o prazo configurado para renovação de informações.  
967 - MessageDlg('Atenção: é necessário o preenchimento/atualização das informações de Patrimônio e Localização Física deste computador. Por favor, confirme as informações que serão apresentadas na tela que será exibida a seguir.', mtInformation, [mbOk], 0);  
968 - boolColeta := true;  
969 - end  
970 - Else if (GetValorDatMemoria('Patrimonio.dt_ultima_renovacao',v_tstrCipherOpened)= '') then  
971 - Begin  
972 - // Solicita o cadastramento de informações de patrimõnio caso ainda não tenha sido cadastrado.  
973 - boolColeta := true;  
974 - end;  
975 -  
976 - if boolColeta then  
977 - Begin  
978 - SetValorDatMemoria('Col_Patr.Inicio', FormatDateTime('hh:nn:ss', Now), v_tstrCipherOpened1);  
979 - log_diario('Coletando informações de Patrimônio e Localização Física.');  
980 - v_configs := GetValorDatMemoria('Patrimonio.Configs',v_tstrCipherOpened);  
981 - log_DEBUG('Configurações obtidas: '+v_configs);  
982 -  
983 - MontaInterface;  
984 - MontaCombos;  
985 - RecuperaValoresAnteriores;  
986 -  
987 - End;  
988 - Except  
989 - SetValorDatMemoria('Col_Patr.nada','nada', v_tstrCipherOpened1);  
990 - SetValorDatMemoria('Col_Patr.Fim', '99999999', v_tstrCipherOpened1);  
991 - CipherClose(g_oCacic.getCacicPath + 'temp\col_patr.dat', v_tstrCipherOpened1);  
992 - g_oCacic.Free();  
993 - Application.Terminate;  
994 - End;  
995 - End;  
996 - End;  
997 - end;  
998 -End;  
999 -  
1000 -  
1001 -end.  
col_patr/xml.pas
@@ -1,34 +0,0 @@ @@ -1,34 +0,0 @@
1 -unit XML;  
2 -  
3 -  
4 -interface  
5 -  
6 -Uses LibXmlParser, SysUtils, dialogs;  
7 -  
8 -Function XML_RetornaValor(Tag : String; Fonte : String) : String;  
9 -  
10 -implementation  
11 -  
12 -  
13 -Function XML_RetornaValor(Tag : String; Fonte : String): String;  
14 -VAR  
15 - Parser : TXmlParser;  
16 -begin  
17 - Parser := TXmlParser.Create;  
18 - Parser.Normalize := TRUE;  
19 - Parser.LoadFromBuffer(PAnsiChar(Fonte));  
20 - Parser.StartScan;  
21 - WHILE Parser.Scan DO  
22 - Begin  
23 - if (Parser.CurPartType in [ptContent, ptCData]) Then // Process Parser.CurContent field here  
24 - begin  
25 - if (UpperCase(Parser.CurName) = UpperCase(Tag)) then  
26 - Begin  
27 - Result := Parser.CurContent;  
28 - end;  
29 - end;  
30 - end;  
31 - Parser.Free;  
32 -end;  
33 -  
34 -end.