procedure ReadIniSectionW(const FileName, Section: WideString; ReadValues: Boolean; out Idents, Values: TWideStringDynArray); var s_section: WideString; procedure add_ident(const s_ident: WideString); var s_buf, s_value: WideString; i: Integer; begin s_buf := Trim(s_ident); if s_buf <> '' then begin if ReadValues then s_value := ReadIniValueW(FileName, s_section, s_buf) else s_value := ''; for i := Low(Idents) to High(Idents) do if WideSameText(s_buf, Idents[i]) then begin Values[i] := s_value; Exit; end; SetLength(Idents, Length(Idents) + 1); SetLength(Values, Length(Idents)); Idents[High(Idents)] := s_buf; Values[High(Values)] := s_value; end; end; var s_buf: WideString; p_section: PWideChar; n, i, len, start_pos: Integer; begin s_section := Trim(Section); if s_section = '' then begin ReadValues := False; p_section := nil; end else p_section := PwideChar(s_section); s_buf := ''; repeat len := Length(s_buf) + BUF_SIZE; SetLength(s_buf, len); s_buf[len] := High(s_buf[len]); n := GetPrivateProfileStringW( p_section, nil, nil, PWideChar(s_buf), len, PWideChar(FileName)); until (n < len - 2) or (s_buf[len] <> #0); if n > 0 then begin start_pos := 1; for i := 1 to n do if s_buf[i] = #0 then begin add_ident(Copy(s_buf, start_pos, i - start_pos)); start_pos := i + 1; end; if start_pos <= n then add_ident(Copy(s_buf, start_pos, n - start_pos + 1)); end; end; procedure ReadIniSectionsW(const FileName: WideString; out Sections: TWideStringDynArray); var dummy: TWideStringDynArray; begin ReadIniSectionW(FileName, '', False, Sections, dummy); end; |