unit DemoFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, xmldom, XMLIntf, StdCtrls, msxmldom, XMLDoc;
type
TDemoForm =
class(TForm)
XMLDoc: TXMLDocument;
Memo: TMemo;
AddButton: TButton;
InitButton: TButton;
procedure InitButtonClick(Sender: TObject);
procedure AddButtonClick(Sender: TObject);
private
FNextPartNumber: cardinal;
ItemList: IXMLNode;
function GetNextPartNumber: cardinal;
public
procedure AddItem(sDesc:
string);
procedure InitDoc;
property NextPartNumber: cardinal
read GetNextPartNumber
write FNextPartNumber;
end;
var
DemoForm: TDemoForm;
implementation
{$R *.dfm}
procedure TDemoForm.AddItem(sDesc:
string);
begin
with ItemList.AddChild('
ItemDetail')
do begin
AddChild('
Part').Text := IntToStr(NextPartNumber);
AddChild('
Desc').Text := sDesc;
end;
end;
function TDemoForm.GetNextPartNumber: cardinal;
begin
Inc(FNextPartNumber);
Result := FNextPartNumber;
end;
procedure TDemoForm.InitDoc;
var
nDetail: IXMLNode;
begin
xmlDoc.DocumentElement := xmlDoc.CreateElement('
Orders', '
');
with xmlDoc.DocumentElement
do begin
AddChild('
OrderHeader');
nDetail := AddChild('
OrderDetail');
end;
ItemList := nDetail.AddChild('
ListOfItemDetail');
end;
procedure TDemoForm.InitButtonClick(Sender: TObject);
begin
InitDoc;
Memo.Lines.Assign(xmlDoc.XML);
end;
procedure TDemoForm.AddButtonClick(Sender: TObject);
var
sDesc:
string;
begin
sDesc := '
Description';
if InputQuery('
New item', '
Description', sDesc)
and (sDesc <> '
')
then begin
AddItem(sDesc);
Memo.Lines.Assign(xmlDoc.XML);
end;
end;
end.