Board index » delphi » Quick question: Max length for Format

Quick question: Max length for Format

Hi,

is there a max length for strings, when one use Format-function?
I receive a eConvertError="Format result longer than 4096", but have not
found anything about this in the helpfiles?

thanks,

Per

 

Re:Quick question: Max length for Format


On Sun, 2 Nov 1997 15:51:13 +0100, "Per Larsen" <lind...@po.ia.dk>
wrote:

Quote
>Hi,

>is there a max length for strings, when one use Format-function?
>I receive a eConvertError="Format result longer than 4096", but have not
>found anything about this in the helpfiles?

In the Sysutils.pas source, the origin of this limit can be seen:
Format calls FormatBuf with a buffer of size of 4096.  You can work
around this limitation by calling FormatBuf directly yourself, but you
have to create the buffer in advance.  Maybe a loop that tries Format
first, then if it fails with that error, tries larger and larger
buffers?  You definitely want some upper limit, just in case some bug
in your program or the RTL means that the loop would never terminate.

From the look of the code, FormatBuf doesn't set the #0 or a string
length on the result, so don't forget a SetLength call afterwards.

Re:Quick question: Max length for Format


On Sun, 02 Nov 1997 16:31:24 GMT, dmurd...@pair.com (Duncan Murdoch)
wrote:

Quote
>On Sun, 2 Nov 1997 15:51:13 +0100, "Per Larsen" <lind...@po.ia.dk>
>wrote:

>>Hi,

>>is there a max length for strings, when one use Format-function?
>>I receive a eConvertError="Format result longer than 4096", but have not
>>found anything about this in the helpfiles?

>In the Sysutils.pas source, the origin of this limit can be seen:
>Format calls FormatBuf with a buffer of size of 4096.  You can work
>around this limitation by calling FormatBuf directly yourself, but you
>have to create the buffer in advance.  Maybe a loop that tries Format
>first, then if it fails with that error, tries larger and larger
>buffers?  You definitely want some upper limit, just in case some bug
>in your program or the RTL means that the loop would never terminate.

>From the look of the code, FormatBuf doesn't set the #0 or a string
>length on the result, so don't forget a SetLength call afterwards.

FYI, the version of Format in Delphi 3.01 does not have this 4K limit
anymore. They actually implement it very similar to what Duncan
describes here.

--
Hallvard Vassbotn
Falcon R&D, Reuters Norge

Re:Quick question: Max length for Format


Hi Per,

this has been changed in Delphi 3.01, the format string now can be
longer.

"Per Larsen" <lind...@po.ia.dk> schrieb am Sun, 2 Nov 1997 15:51:13
+0100:

Quote
>Hi,

>is there a max length for strings, when one use Format-function?
>I receive a eConvertError="Format result longer than 4096", but have not
>found anything about this in the helpfiles?

--
BetaSoft
http://www.{*word*104}city.de/user/10794/delphi.htm
email: betas...@kagi.com

Other Threads