动态record数组的应用

最近用到了record类型的数组,主要涉及到record类型动态的创建与添加,实例代码如下:(主要功能为从XML文件中读取数据,并放在record数组中,当然,如果不是从XML文件中读取就省了很多步骤了)

procedure TForm1.btn2Click(Sender: TObject); var XMLDocChar: TXMLDocument; Root:Ixmlnode; i,LangLength:integer; function LoadData(RootNode:Ixmlnode):boolean; var j:integer; begin for j := 0 to Root.ChildNodes.Count- 1 do begin if Root.ChildNodes[j].NodeName<>'' then begin if Root.ChildNodes[j].Attributes['Name']<>null then begin SetLength(LangList,Length(LangList)+1); LangLength:= Length(LangList)-1; LangList[LangLength].LangName:=Root.ChildNodes[j].Attributes['Name']; end else continue; if Root.ChildNodes[j].Attributes['Text']<>null then LangList[LangLength].LangText:=Root.ChildNodes[j].Attributes['Text']; end; end; end; begin XMLDocChar:=TXMLDocument.Create(application); XMLDocChar.LoadFromFile('./language/frxrcClass_zh-CN.xml'); XMLDocChar.Active:=true; Root:=XMLDocChar.DocumentElement; LoadData(Root); XMLDocChar.LoadFromFile('./language/frxrcDesgn_zh-CN.xml'); XMLDocChar.Active:=true; Root:=XMLDocChar.DocumentElement; LoadData(Root); for i := 0 to Length(LangList) - 1 do begin mmo1.Lines.Add('Name:'+LangList[i].LangName+' Text:'+LangList[i].LangText); end; FreeAndNil(XMLDocChar); end;

你可能感兴趣的:(xml,function,null,Integer,application)