Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to merge the sections of two TIniFiles Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
23-Nov-03
Category
Algorithm
Language
Delphi 2.x
Views
98
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

Imagine there are two win.ini files and I want to combine both together. Some of 
the common sections and keys/ values are the same in each but they differ in their 
data generally. How could I merge the two together to get an ini file that contains 
all the data from both in the right places?

Answer:

Iterate over the sections in the source file. For each section, iterate over the 
names. If there is a name in Source that already exists in Dest, Dest's copy will 
be overwritten.

1   { ... }
2   var
3     Source, Dest: TIniFile;
4     SectionNames: TStrings;
5     i: Integer;
6   begin
7     SectionNames := TStringList.Create;
8     try
9       Source.ReadSections(SectionNames);
10      for i := 0 to SectionNames.Count - 1 do
11      begin
12        MergeSection(Source, Dest, SectionNames[i]);
13      end;
14    finally
15      SectionNames.Free;
16    end;
17  end;
18  
19  procedure MergeSection(Source, Dest: TIniFile; const SectionName: string);
20  var
21    i: Integer;
22    Section: TStrings;
23    Name, Value: string;
24  begin
25    Section := TStringList.Create;
26    try
27      Source.ReadSection(SectionName, Section);
28      for i := 0 to Section.Count - 1 do
29      begin
30        Name := Section.Names[i];
31        Value := Section.Values[Name];
32        Dest.WriteString(SectionName, Name, Value);
33      end;
34    finally
35      Section.Free;
36    end;
37  end;



			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC