Delphi INI 读取字符串限制

标签 delphi limit ini

我将应用程序的设置存储在 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/

相关文章:

delphi - 为什么条件断点会使我的程序速度减慢这么多?

delphi - 为什么实现接口(interface)的类在泛型中使用时与接口(interface)类型不兼容?

java - 更新 INI/属性文件

java - Java 中的命令行参数与文件属性 (*.properties) 与系统属性 (-D)

PHP 错误未显示在浏览器中

delphi - 是否可以使用 RTTI 获取接口(interface)上 GUID 的值?

delphi - 如何发现远程桌面 session 的图像质量设置?

R ggplot2 scale_y_continuous : Combining breaks & limits

php - 计数限制为另一个表中定义的特定值

javascript - PHP/JavaScript : How I can limit the download speed?