procedure TChildForm.SetHeader(wsXMLHeader: TMemoryStream); var xmlNode,xmlchildNode: IXMLNode; icol,irow,cx,cy:integer; iWidth:integer; i:integer; begin XMLDocument1.Active :=true; XMLDocument1.LoadFromStream(wsXMLHeader,xetUnknown); if XMLDocument1.IsEmptyDoc then exit; xmlNode:=XMLDocument1.DocumentElement; if xmlNode=nil then exit; if xmlNode.NodeName<>'dust' then exit; xmlNode:=xmlNode.ChildNodes.First; while xmlNode<>nil do begin if xmlNode.NodeName='colcount' then begin Grid.ColCount :=strtoint(xmlNode.NodeValue); for i:=0 to Grid.ColCount -1 do FColFieldList.Add('none'); end; if xmlNode.NodeName='rowcount' then Grid.RowCount:=strtoint(xmlNode.NodeValue); if xmlNode.NodeName='fixedcol' then Grid.FixedCols:=strtoint(xmlNode.NodeValue); if xmlNode.NodeName='fixedrow' then Grid.FixedRows:=strtoint(xmlNode.NodeValue); if xmlNode.NodeName='defaultwidth' then Grid.DefaultColWidth:=strtoint(xmlNode.NodeValue); if xmlNode.NodeName='colwidth' then begin icol:=strtoint(xmlNode.Attributes['col']); iWidth:=strtoint(xmlNode.Attributes['width']); Grid.ColWidths[icol]:=iWidth; end; if xmlNode.NodeName='item' then begin if xmlNode.HasChildNodes then begin xmlchildNode:=xmlNode.ChildNodes.First; while xmlChildNode<>nil do begin if xmlChildNode.NodeName='cells' then begin icol:=strtoint(xmlChildNode.Attributes['col']); irow:=strtoint(xmlChildNode.Attributes['row']); Grid.Cells[icol,irow]:=xmlChildNode.Attributes['caption']; cx:=strtoint(xmlChildNode.Attributes['colx']); cy:=strtoint(xmlChildNode.Attributes['rowy']); if not ((cx=0) and (cy=0)) then Grid.MergeCells(iCol,iRow,cx,cy); end; if xmlChildNode.NodeName='fields' then begin i:= strtoint(xmlChildNode.Attributes['col']); if (i>=0) and (i<FcolFieldList.Count) then FColFieldList.Strings[i]:=xmlChildNode.Attributes['name']; end; xmlChildNode:=xmlChildNode.NextSibling; end; end; end; xmlNode:=xmlNode.NextSibling; end;end;这是我的一个读取xml文档对TMS的表格进行设置的例子
var
xmlNode,xmlchildNode: IXMLNode;
icol,irow,cx,cy:integer;
iWidth:integer;
i:integer;
begin
XMLDocument1.Active :=true;
XMLDocument1.LoadFromStream(wsXMLHeader,xetUnknown);
if XMLDocument1.IsEmptyDoc then exit;
xmlNode:=XMLDocument1.DocumentElement;
if xmlNode=nil then exit;
if xmlNode.NodeName<>'dust' then exit;
xmlNode:=xmlNode.ChildNodes.First;
while xmlNode<>nil do
begin
if xmlNode.NodeName='colcount' then
begin
Grid.ColCount :=strtoint(xmlNode.NodeValue);
for i:=0 to Grid.ColCount -1 do
FColFieldList.Add('none');
end;
if xmlNode.NodeName='rowcount' then
Grid.RowCount:=strtoint(xmlNode.NodeValue);
if xmlNode.NodeName='fixedcol' then
Grid.FixedCols:=strtoint(xmlNode.NodeValue);
if xmlNode.NodeName='fixedrow' then
Grid.FixedRows:=strtoint(xmlNode.NodeValue);
if xmlNode.NodeName='defaultwidth' then
Grid.DefaultColWidth:=strtoint(xmlNode.NodeValue); if xmlNode.NodeName='colwidth' then
begin
icol:=strtoint(xmlNode.Attributes['col']);
iWidth:=strtoint(xmlNode.Attributes['width']);
Grid.ColWidths[icol]:=iWidth;
end;
if xmlNode.NodeName='item' then
begin
if xmlNode.HasChildNodes then
begin
xmlchildNode:=xmlNode.ChildNodes.First;
while xmlChildNode<>nil do
begin
if xmlChildNode.NodeName='cells' then
begin
icol:=strtoint(xmlChildNode.Attributes['col']);
irow:=strtoint(xmlChildNode.Attributes['row']);
Grid.Cells[icol,irow]:=xmlChildNode.Attributes['caption'];
cx:=strtoint(xmlChildNode.Attributes['colx']);
cy:=strtoint(xmlChildNode.Attributes['rowy']);
if not ((cx=0) and (cy=0)) then
Grid.MergeCells(iCol,iRow,cx,cy);
end;
if xmlChildNode.NodeName='fields' then
begin
i:= strtoint(xmlChildNode.Attributes['col']);
if (i>=0) and (i<FcolFieldList.Count) then
FColFieldList.Strings[i]:=xmlChildNode.Attributes['name'];
end;
xmlChildNode:=xmlChildNode.NextSibling;
end;
end;
end;
xmlNode:=xmlNode.NextSibling;
end;end;这是我的一个读取xml文档对TMS的表格进行设置的例子
C:\Program Files\Borland\Delphi7\Demos\DbClx\mybasexplorer
http://www.delphibbs.com/delphibbs/DispQ.asp?LID=1819735