Solved

Copying INI Section to another INI File

Posted on 1998-03-11
4
435 Views
Last Modified: 2010-04-04
Hello,

How would I go about copying and entire section of an INI file to another
INI file that already exists?  I've read up on the ReadSection & ReadSection
values functions, but I can't figure out how to use the WriteString function
to get the values from the original INI file.  Any suggestions?

Thanks.
0
Comment
Question by:d4jaj1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Expert Comment

by:Marcelito
ID: 1360405
You can use

GetPrivateProfileString(pchar("SectionName string"),pchar("KeyName string"),
                                 pchar("Default string"),"your buffer",sizeof("your buffer"),
                                 pchar("FileName string"'));

for read from the INI file.

If you want write in an INI file, can use

WritePrivateProfileString(pchar("SectionName string"),pchar("KeyName string"),
                                    pchar("Value string"),pchar("FileName string"));

Good Luck!!!
0
 
LVL 3

Author Comment

by:d4jaj1
ID: 1360406
Few questions, I haven't used either of these functions before.  What exactly is "your buffer" and what size shoudl I allocate to it?  Also, do I have to declare and create it before I use it?  Thanks.
0
 

Expert Comment

by:Marcelito
ID: 1360407
Sorry, "your buffer" is

var  buf:array[0..255] of Char;

and is the variable that contain the value for a key in the INI file.

Success!!!
0
 
LVL 1

Accepted Solution

by:
RJENKINS earned 20 total points
ID: 1360408
try this procedure
you will have to use FileExists function for checking target file

procedure CopyIniSection(OldFile,OldSection,NewFile,NewSection: String);
var
  I: Integer;
  S: TStringList;
  N: TIniFile;
begin
  S := TStringList.Create;
  try
    with TIniFile.Create(OldFile) do
    begin
      ReadSection(OldSection,S);
      N := TIniFile.Create(NewFile);
      try
        for I := 0 to S.Count -1 do
        begin
          N.WriteString(NewSection,S[I],ReadString(OldSection,S[I],''));
        end;
      finally
        N.Free;
      end;
    end;
  finally
    S.Free;
  end;
end;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question