Delphi Wrapper Classes and XML - A Demonstration
(Page 3 of 4 )
Earlier we created a program that loads an XML document into a memo component. In the following section we will create a program that will load an XML document into a DOM and then show the structure in a treeview, which incidentally is the only control in the component collection of Delphi that I think is useful for this kind of exercise.
Loading the document is very simple, as you've seen from the previous example, but showing it in a tree is another matter altogether. Place two treeview components on a form and then add two buttons. Call the treeviews tv and tv1 respectively. Then call the first button "Load" and the other one "Exit." On the form, add an opendialog component (available from the dialog tab) and an xmldocument component (available from the Internet tab).
Below is a listing for the entire application:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
xd: TXMLDocument;
tv: TTreeView;
Button1: TButton;
Button4: TButton;
od: TOpenDialog;
tv1: TTreeView;
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure tv1DblClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
procedure DOMShow(Anode: IXMLNode; TNode: TTreeNode);
{ Private declarations }
public
fn:string;
{ Public declarations }
end;
const
IMG_NODE_ROOT = 0;
IMG_NODE_CLOSED = 1;
IMG_NODE_OPEN = 2;
IMG_NODE_ROOT2 = 3;
IMG_NODE_CLOSED2 = 4;
IMG_NODE_OPEN2 = 5;
var
Form1: TForm1;
implementation
{$R *.dfm}
First we start by defining some variables, procedures and functions. The listing also shows the components that is used in the application. It is a good place to verify what components you need to built the application itself:
procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;
Next: Second Part of Code >>
More Delphi-Kylix Articles
More By David Web