Why does Format crash when anything but “%s” is used with a Variant?

我的梦境 提交于 2019-12-05 01:05:26

It is a limitation of the function. In Delphi XE, the relevant part in SysUtils starts at line 10870, which looks like this:

@CvtVariant:
        CMP     CL,'S'
        JNE     @CvtError

This is called for any variant argument. The CL register have the type required by the format string for that particular argument, for anything different than 'S', the exception is raised.

It's a limitation of the function. For a more feature-rich version of Format, try the WideFormat function from the JCL. (I'm its author.) It supports Variants of various types, Boolean, and TClass. It also accepts character-pointer types for the %p format, and Int64 and Variant values for index arguments.

Despite its extensions, it was removed from the JCL distribution about a year ago because its primary target was Delphi 5, which didn't provide a native WideString version of Format, and the JCL no longer supports Delphi 5. The last revision that included it was 3140.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!