I wonder why TIniFile.ReadString sets the maximum value size to 2047 without checking the actual value in the file and without limiting the value size in TIniFile.WriteString.
Stackoverflow accepted the maximum allowed value to be 65,535
https://stackoverflow.com/questions/10507927/getprivateprofilestring-buffer-length
https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getprivateprofilestringw
DWORD GetPrivateProfileStringW(
[in] LPCWSTR lpAppName,
[in] LPCWSTR lpKeyName,
[in] LPCWSTR lpDefault,
[out] LPWSTR lpReturnedString,
[in] DWORD nSize,
[in] LPCWSTR lpFileName
)
...
If neither lpAppName nor lpKeyName is NULL and the supplied destination buffer is too small to hold the requested string, the string is truncated and followed by a null character, and the return value is equal to nSize minus one.
But if the developers of System.IniFiles.TIniFile implemented a limit of 2047, then why did they do it only for TIniFile.ReadString (without throwing an exception when exceeded), but not for TIniFile.WriteString.
unit System.IniFiles
...
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;
procedure TIniFile.WriteString(const Section, Ident, Value: string);
begin
if not WritePrivateProfileString(MarshaledString(Section), MarshaledString(Ident),
MarshaledString(Value), MarshaledString(FFileName)) then
raise EIniFileException.CreateResFmt(@SIniFileWriteError, [FileName]);
end;