如何合并两个TINIfile实例中的条目?(How to merge entries from two TINIfile instances?)

编程入门 行业动态 更新时间:2024-10-25 20:23:05
如何合并两个TINIfile实例中的条目?(How to merge entries from two TINIfile instances?)

有没有办法将一个TIniFile实例的条目合并到另一个实例?

Is there a way to merge entries from one TIniFile instance to another?

最满意答案

以下是一个可以将两个INI文件合并到一个新的输出INI文件中的过程:

procedure MergeIniFiles(const FromFilename, ToFilename, OutputFilename: String; const Overwrite: Boolean); var IniFrom, IniTo, IniOut: TIniFile; Sec: TStringList; Val: TStringList; X, Y: Integer; S, N, V: String; begin IniFrom:= TIniFile.Create(FromFilename); IniTo:= TIniFile.Create(ToFilename); IniOut:= TIniFile.Create(OutputFilename); Sec:= TStringList.Create; Val:= TStringList.Create; try IniFrom.ReadSections(Sec); for X := 0 to Sec.Count-1 do begin S:= Sec[X]; IniFrom.ReadSection(S, Val); for Y := 0 to Val.Count-1 do begin N:= Val[Y]; V:= IniFrom.ReadString(S, N, ''); IniOut.WriteString(S, N, V); end; end; IniTo.ReadSections(Sec); for X := 0 to Sec.Count-1 do begin S:= Sec[X]; IniTo.ReadSection(S, Val); for Y := 0 to Val.Count-1 do begin N:= Val[Y]; V:= IniTo.ReadString(S, N, ''); if Overwrite then begin IniOut.WriteString(S, N, V); end else begin if not IniOut.ValueExists(S, N) then IniOut.WriteString(S, N, V); end; end; end; finally Val.Free; Sec.Free; IniOut.Free; IniTo.Free; IniFrom.Free; end; end;

Here's a procedure which can merge two INI files together into a new output INI file:

procedure MergeIniFiles(const FromFilename, ToFilename, OutputFilename: String; const Overwrite: Boolean); var IniFrom, IniTo, IniOut: TIniFile; Sec: TStringList; Val: TStringList; X, Y: Integer; S, N, V: String; begin IniFrom:= TIniFile.Create(FromFilename); IniTo:= TIniFile.Create(ToFilename); IniOut:= TIniFile.Create(OutputFilename); Sec:= TStringList.Create; Val:= TStringList.Create; try IniFrom.ReadSections(Sec); for X := 0 to Sec.Count-1 do begin S:= Sec[X]; IniFrom.ReadSection(S, Val); for Y := 0 to Val.Count-1 do begin N:= Val[Y]; V:= IniFrom.ReadString(S, N, ''); IniOut.WriteString(S, N, V); end; end; IniTo.ReadSections(Sec); for X := 0 to Sec.Count-1 do begin S:= Sec[X]; IniTo.ReadSection(S, Val); for Y := 0 to Val.Count-1 do begin N:= Val[Y]; V:= IniTo.ReadString(S, N, ''); if Overwrite then begin IniOut.WriteString(S, N, V); end else begin if not IniOut.ValueExists(S, N) then IniOut.WriteString(S, N, V); end; end; end; finally Val.Free; Sec.Free; IniOut.Free; IniTo.Free; IniFrom.Free; end; end;

更多推荐

本文发布于:2023-07-30 00:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1320820.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条目   实例   两个   TINIfile   instances

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!