Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ini.ReadString problem 1

Status
Not open for further replies.

abcfantasy

Programmer
Jun 3, 2006
110
DK
I've got a string saved in an ini file of about 3500 characters. Then I read that string in a string variable, and it only copies 2047 characters.

Any help on this?
Thanks
Andrew

ABC -
 
Probably you have a #0 in the middle.

With the debugger, show the string characters 2045..2049.

Or delete anything but the string from the ini file and verify it have the due size.

buho (A).
 
Ha, I had exactly the same problem yesterday...

Fact is that TIniFile.Readstring defines a buffer 0f [0..2047] of char, effectively limiting the largest string to be read to be just 2 kB - 1 char.

I got around this by replacing the ini.readstring bij a function ReadBigIniString, that I coded like this:
Code:
    Function ReadBigIniString(FileName_: string; const Section, Ident, Default: string): string;
    Var Buffer: array[0..16383] of Char;
    Begin
        SetString(Result, Buffer, GetPrivateProfileString(PChar(Section),
          PChar(Ident), PChar(Default), Buffer, SizeOf(Buffer), PChar(FileName_)));
    End;  // alternative TIniFile.ReadString, with 16 kB buffer instead of 2 kB

Watch the extra FileName_ parameter in front of the original params.
Didn't feel like overloading the original class, so just made a quick workaround.

Btw, the WriteString has no limit like this.

HTH
TonHu
 
I believe that there is a 2KB limit on the size of strings (including the terminating byte) in Windows XP INI files. I recall the limit in Windows 98 being 32KB - but I may be wrong about that.

Unfortunately, I cannot find any documentation that confirms this.

Andrew
Hampshire, UK
 
>>
Fact is that TIniFile.Readstring defines a buffer 0f [0..2047] of char, effectively limiting the largest string to be read to be just 2 kB - 1 char.
<<

Arrrrggghhh!

buho (A).
 
It will recompile automatically, but better do not modify the original file.

Copy IniFiles.PAS to another directory, change the file name (like to "PatchedIniFiles.PAS"), modify the copy and use it.

I any way, document de modification (use a keyword like *PATCH* in the source to find the changes quickly).

---------
Actually, ReadString is virtual; the right way here is to make your own descendant.
--------

buho (A).
 
That's why I choose to replace the method with a direct function, didn't want to modify the original source.
Ofcourse the extra parameter changes the use of the function, but as there is no real change to the actual use, GetPrivateProfileString is called with a filename anyway, so probably the file is opened and closed at every call, there should be no performance change. I changed my use from:
Code:
...).Lines.CommaText := Ini_.ReadString(icFILE + IntToStr(m),...
to:
Code:
...).Lines.CommaText := ReadBigIniString(Ini_.FileName, icFILE + IntToStr(m),...

HTH
TonHu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top