OK, dann sollte man auch nicht jedesmal 'columns' neu erstellen.
Delphi-Quellcode:
procedure SetItem(ColumnName: String; Visible: Boolean; Position, Width: Integer);
...
begin
xmlColNode := xmlDoc.documentElement.selectSingleNode('columns');
if not Assigned(xmlColNode) then
begin
xmlColNode := xmlDoc.createElement('column');
xmlDoc.documentElement.appendChild(xmlColNode);
end;
xmlNode := xmlColNode.selectSingleNode(ColumnName);
if Assigned(xmlNode) then
begin
xmlNode.selectSingleNode('visible').Text := Visible;
xmlNode.selectSingleNode('position').Text := Position;
xmlNode.selectSingleNode('width').Text := Width;
end
else
begin
xmlNode := xmlDoc.createElement(ColumnName);
xmlColNode.appendChild(xmlNode);
NewSub := xmlDoc.createElement('visible');
NewSub.text := Visible;
xmlNode.appendChild(NewSub);
NewSub := xmlDoc.createElement('position');
NewSub.text := Position;
xmlNode.appendChild(NewSub);
NewSub := xmlDoc.createElement('width');
NewSub.text := Width;
xmlNode.appendChild(NewSub);
end;
end;
und wenn du ganz auf Nummer sichergehn willst, dann:
(eine leere Try-Except-Behandlung ist nicht sonderlich schön)
Delphi-Quellcode:
procedure SetItem(ColumnName: String; Visible: Boolean; Position, Width: Integer);
...
begin
xmlColNode := xmlDoc.documentElement.selectSingleNode('columns');
if not Assigned(xmlColNode) then
begin
xmlColNode := xmlDoc.createElement('column');
xmlDoc.documentElement.appendChild(xmlColNode);
end;
xmlNode := xmlColNode.selectSingleNode(ColumnName);
if not Assigned(xmlNode) then
begin
xmlNode := xmlDoc.createElement(ColumnName);
xmlColNode.appendChild(xmlNode);
end;
xmlSubNode := xmlNode.selectSingleNode('visible');
if not Assigned(xmlSubNode) then
begin
xmlSubNode:= xmlDoc.createElement('visible');
xmlNode.appendChild(xmlSubNode);
end;
xmlSubNode.Text := Visible;
xmlSubNode := xmlNode.selectSingleNode('position');
if not Assigned(xmlSubNode) then
begin
xmlSubNode:= xmlDoc.createElement('position');
xmlNode.appendChild(xmlSubNode);
end;
xmlSubNode.Text := Position;
xmlSubNode := xmlNode.selectSingleNode('width');
if not Assigned(xmlSubNode) then
begin
xmlSubNode:= xmlDoc.createElement('width');
xmlNode.appendChild(xmlSubNode);
end;
xmlSubNode.Text := Width;
end;
(jetzt weiß ich wieder, warum ich
MSXML nicht mag
...
Unmassen Zeilen an Code, wo doch 3 Zeilen gereicht hätten)