我将应用程序的设置存储在 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;
最佳答案
解决方案很简单。
扩展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;
关于Delphi INI 读取字符串限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38160523/