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;
INI files have a 64KB limit of the data they can store.
Reading From INI The TIniFile class has several "read" methods. The ReadString reads a string value from a key, ReadInteger. ReadFloat and similar are used to read a number from a key. All "read" methods have a default value that can be used if the entry does not exist.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With