Solved

Copying INI Section to another INI File

Posted on 1998-03-11
4
442 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 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