Solved

Copying INI Section to another INI File

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

16 Experts available now in Live!

Get 1:1 Help Now