Solved

Copying INI Section to another INI File

Posted on 1998-03-11
4
397 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
  • 2
4 Comments
 

Expert Comment

by:Marcelito
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now