我将应用程序的设置存储在INI文件中.我读到二进制条目存在2kb的限制,因此我将二进制编码为字符串并将值存储为字符串(writestring).检查文件时,似乎所有字符串都按预期存储.
当试图读回来时,似乎只读取了2047个字符,因此在将其解码回流时,它会失败.
显然,似乎字符串也有2kb的限制,但我想知道是否那样或者我做错了什么.如果有这样的限制,任何想法我怎么能绕过它?
谢谢
编辑:傻我,我去了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;
Run Code Online (Sandbox Code Playgroud)
解决方案很简单.
扩展TInifile
并插入您自己的版本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;
Run Code Online (Sandbox Code Playgroud)