end;
end;
procedure TXMLOption.InsertUser(uid:string;muser:RecUser);
var
xfind:IXMLDOMNode;
xuser:IXMLDOMElement;
xroot:IXMLDOMElement;
xpath:string;
begin
if not FActive then exit;
xpath:=UsersTag+''[''+U_Id+''="''+uid+''"]'';
xfind:=FXMLDoc.documentElement.selectSingleNode(xpath);
//如果没有找到, xfind=nil 则在文件的末尾插入
//如果找到,xfind<>nil 则在找到的纪录前面插入
xroot:=FXMLDoc.documentElement;
xuser :=IXMLDOMElement(xroot.insertBefore(FXMLDoc.CreateElement(UsersTag),xfind));
AddSimpleElement(xuser,U_Id,muser.U_Id);
AddSimpleElement(xuser,U_Name,muser.U_Name);
AddSimpleElement(xuser,U_Sex,muser.U_Sex);
AddSimpleElement(xuser,U_Birth,muser.U_Birth);
AddSimpleElement(xuser,U_Tel,muser.U_Tel);
AddSimpleElement(xuser,U_Addr,muser.U_Addr);
AddSimpleElement(xuser,U_PostCode,muser.U_PostCode);
AddSimpleElement(xuser,U_Email,muser.U_Email);
FXMLDoc.save(FFilename);
end;
procedure TXMLOption.RemoveUser(uid:string);
var
xfind:IXMLDOMNode;
xroot:IXMLDOMElement;
xpath:string;
begin
if not FActive then exit;
xpath:=UsersTag+''[''+U_Id+''="''+uid+''"]'';
xfind:=FXMLDoc.documentElement.selectSingleNode(xpath);
if xfind<>nil then
begin
xroot:=FXMLDoc.documentElement;
xroot.removeChild(xfind);
FXMLDoc.save(FFilename);
end;
end;
procedure TXMLOption.ReplaceUser(uid:string;newuser:RecUser);
var
xfind,newnode:IXMLDOMNode;
xroot:IXMLDOMElement;
xpath:string;
begin
if not FActive then exit;
xpath:=UsersTag+''[''+U_Id+''="''+uid+''"]'';
xfind:=FXMLDoc.documentElement.selectSingleNode(xpath);
//如果没有找到,则不做替换
if xfind<>nil then
begin
newnode:=xfind.cloneNode(true);
newnode.selectSingleNode(U_Id).text:=newuser.U_Id;
newnode.selectSingleNode(U_Name).text:=newuser.U_Name;
newnode.selectSingleNode(U_Sex).text:=newuser.U_Sex;
newnode.selectSingleNode(U_Birth).text:=newuser.U_Birth;
newnode.selectSingleNode(U_Tel).text:=newuser.U_Tel;
newnode.selectSingleNode(U_Addr).text:=newuser.U_Addr;
newnode.selectSingleNode(U_PostCode).text:=newuser.U_PostCode;
newnode.selectSingleNode(U_Email).text:=newuser.U_Email;
xroot:=FXMLDoc.documentElement;
xroot.replaceChild(newnode,xfind);
FXMLDoc.save(FFilename);
end;
end;
function TXMLOption.FindUser(userid:widestring):boolean;
var
xuser:IXMLDOMNode;
xpath:string;
begin
result:=fa