5
votes

I'm storing my application's settings in an INI file. I read that there is a limitation of 2kb for a binary entry so I encoded the binary into a string and stored the value as string (writestring). When checking the file, it seems that all the string was stored as expected.

When trying to read it back, it seems that only 2047 characters were read so when decoding it back to a stream, it fails.

Apparently it seems there is a 2kb limitation for string as well but I was wondering if that is that or maybe I did something wrong. If there's such a limitation, any idea how can I bypass it?

Thanks

EDIT: silly me, I went to system.inifiles and it says in the code

function TIniFile.ReadString(const Section, Ident, Default: string): string;
var
  Buffer: array[0..2047] of Char; <<<<<<<<<<<<<<<<
begin

  SetString(Result, Buffer, GetPrivateProfileString(MarshaledString(Section),
    MarshaledString(Ident), MarshaledString(Default), Buffer, Length(Buffer),
    MarshaledString(FFileName)));
end;
1
Which delphi version?Johan
Delphi xe though it might be related to INI in generalAmos
Using the TMemIniFile, there is no such limitation.LU RD
FYI TCustomIniFile.WriteBinaryStream did exactly what you are doing, just use it with TMemIniFile or with your inherited classSir Rufo
Forget INI files at all, they are old and slow.smooty86

1 Answers

6
votes

The solution is easy.

Extend TInifile and insert your own version of ReadString.

TMyIniFile = class(TInifile)
      function ReadString(const Section, Ident, Default: string): string; override;
end;

function TMyIniFile.ReadString(const Section, Ident, Default: string): string;
var
  Buffer: array[0..largenumber] of Char;
begin                                
  SetString(Result, Buffer, GetPrivateProfileString(MarshaledString(Section),
    MarshaledString(Ident), MarshaledString(Default), Buffer, Length(Buffer),
    MarshaledString(FFileName)));
end;