Solved

Copying INI Section to another INI File

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 100
Strange behavior when a form is closed 6 58
Working with hours 3 58
CheckListBox usage 3 59
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…
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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