Description | Hierarchy | Fields | Methods | Properties |
type tTidyBus = class(TObject)
Class to facilitate minor editing operations on a TidyDoc.
Since the TidyDoc's tree structure is effectively read-only, the tTidyBus object is designed to emulate the ability to move, copy, edit and delete the nodes of a TidyDoc tree.
Instead of modifying the tree itself, tTidyBus recreates a new text document in its ResultBuf, based on the behavior defined by the InsertMode and CopyMode properties, and the elements pointed to in the SourceNode and TargetNode properties, and the text contained in the Cargo buffer.
For a basic example of how to use this object, see the \tidypas\demo\tidymove.pas
demo program.
Modifying a document using a tTidyBus is really not very efficient, since the entire document must be parsed, reparsed, recreated, and reparsed again each time a change is made. It is intended only to make small "one-shot" changes to the document. If you need a more fluid-like DOM, you would probably be better off exporting tidylib's output to a more suitable writer.
constructor Create; |
|
destructor Destroy; override; |
|
procedure Clear; |
|
procedure Execute(doc:pTidyDoc;PickupProc:tNodeCallback); |
|
procedure AddCargo(p:pChar); |
property TargetNode: pTidyNode (read/write); |
|
property SourceNode: pTidyNode (read/write); |
|
property InsertMode: tTidyBusInsertMode (read/write); |
|
property CopyMode: tTidyBusCopyMode (read/write); |
|
property ResultBuf: tTidyBuffer (read-only); |
|
property Cargo: pChar (read-only); |
constructor Create; |
|
Creates a new instance of tTidyBus. |
destructor Destroy; override; |
|
Destroys this instance of tTidyBus. |
procedure Clear; |
|
Frees the memory allocated to the Cargo and Result buffers. ( Called automatically on |
procedure Execute(doc:pTidyDoc;PickupProc:tNodeCallback); |
|
The Execute method will first invoke the ForEachNode procedure on the root node of the TidyDoc, using your The purpose of your PickupProc is to search the document tree, and set the desired values of the tTidyBus's SourceNode, TargetNode, and Cargo properties. The PickupProc is also responsible for calling itself to recurse any child nodes. If you have some other means of initializing the SourceNode, TargetNode, and Cargo fields, you can safely set the PickupProc argument to After the PickupProc has completed, tTidyBus will traverse the document tree again, and generate a new textual document in the ResultBuffer, based on the criteria established by your property settings. Note that the original TidyDoc is not actually modified, and no validation is performed on the text of the newly-created ResultBuffer. |
procedure AddCargo(p:pChar); |
|
Appends text to the tTidyBus Cargo buffer |
property TargetNode: pTidyNode (read/write); |
|
Reference node for where the Cargo text is to be written. Can be NIL if CopyMode is cmEdit or cmDelete |
property SourceNode: pTidyNode (read/write); |
|
Reference node for where the Cargo text was obtained. |
property InsertMode: tTidyBusInsertMode (read/write); |
|
This property controls where the Cargo is to be written, relative to the TargetNode ( see tTidyBusInsertMode ) |
property CopyMode: tTidyBusCopyMode (read/write); |
|
This property controls how the SourceNode is to be updated ( see tTidyBusCopyMode ) |
property ResultBuf: tTidyBuffer (read-only); |
|
The resulting buffer where the new document is written. |
property Cargo: pChar (read-only); |
|
Provides access to the text of the tTidyBus Cargo buffer |