比如说INI文件内容是
[a]
a1=a1
a2=a2
a3=a3
我想获得 [a]下面所有的KEY和值 
我用下面这段代码只能获得 a1=a1 不知道为什么 ,请个位高手帮忙解决
var
buffer: pchar;
size: dword;
begin
size := 32767;
GetMem(buffer, size);
ZeroMemory(pchar(buffer), size);
GetPrivateProfileSection('api',buffer,size,pchar(ExtractFilePath(ParamStr(0))+'123.ini'));
memo1.Lines.Add(buffer);
FreeMem(buffer);end;

解决方案 »

  1.   

    Iniread:Tinifile;
    sl:tstrings;sl:= TStringList.Create;
    iniread:=TIniFile.Create(ExtractFilePath(Application.ExeName )+INIFile);
    iniRead.ReadSectionValues('a',sl);
      

  2.   

    我想使用API 获取吗?那位高手牺牲一下您宝贵的时间给我写个例子吧。
    网上貌似都是C++ 的看不懂哦。。 我新手 呵呵
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
      procedure ReadSection(const Section: string; FileName: String);
      const BufSize = 16384;
      var
        Buffer, Buf, P: PChar;
      begin
        GetMem(Buffer, BufSize);
        GetMem(Buf,BufSize);
          try
            if GetPrivateProfileString(PChar(Section), nil, nil, Buffer, BufSize,
              PChar(FileName)) <> 0 then
            begin
              P := Buffer;
              while P^ <> #0 do
              begin
                GetPrivateProfileString(PChar(Section), p, nil, Buf, BufSize,PChar(FileName));
                self.Memo1.Lines.Add( buf );
                Inc(P, StrLen(P) + 1);
              end;
            end;
        finally
          FreeMem(Buffer, BufSize);
          FreeMem(Buf, BufSize);
        end;
      end;
    begin  ReadSection('a','d:\123.ini');end;
      

  4.   

    您有QQ吗 ? 我QQ7956214 
    我是新手。。 不知道如何写哦。。
      

  5.   

    有问题你就在这里讨论吧P就是等号前边的部分
    self.Memo1.Lines.Add( buf );
    修改成=〉
    self.Memo1.Lines.Add( p );
      

  6.   

    还有什么问题你可以看看inifiles单元里是怎么实现的,最好的办法是你用Tinifile类来实现,然后跟踪到inifiles里看看是怎样使用api来实现的,修改一下就OK了
      

  7.   

    这样可以简单得到
    procedure TForm1.Button1Click(Sender: TObject);
    var IniFile:TIniFile;
    begin
      try
        IniFile:=TIniFile.Create('C:\Documents and Settings\Administrator\桌面\test.ini');
        IniFile.ReadSection('a',ListBox1.Items);
        IniFile.ReadSectionValues('a',ListBox2.Items);
      finally
        IniFile.Free;
      end;
    end;