格式为什么拒绝从XE4开始的过程地址参数 [英] Why does Format reject procedure address arguments starting with XE4
问题描述
考虑这个程序:
{$APPTYPE CONSOLE}
uses
System.SysUtils;
procedure Foo;
begin
end;
type
TProcedure = procedure;
const
FooConst: TProcedure = Foo;
var
FooVar: TProcedure = Foo;
P: Pointer;
{$TYPEDADDRESS ON}
begin
P := @Foo;
Writeln(Format('%p', [P]));
Writeln(Format('%p', [@FooConst]));
Writeln(Format('%p', [@FooVar]));
Writeln(Format('%p', [@Foo]));
Readln;
end.
该程序在XE3上编译并运行,并产生以下输出:
This program compiles and runs on XE3 and produces the following output:
00419FB8
00419FB8
00419FB8
00419FB8
在XE4和更高版本的程序无法编译,错误消息在这两行:
On XE4 and later the program fails to compile, with error messages on both of these lines:
Writeln(Format('%p', [@FooConst]));
Writeln(Format('%p', [@FooVar]));
[dcc32 Error] E2250 There is no overloaded version of 'Format' that can be called
with these arguments
在XE4,XE5和XE6上,程序在 $ TYPEDADDRESS
已关闭。在XE7上,程序无法编译,不管 $ TYPEDADDRESS
的设置如何。
On XE4, XE5 and XE6, the program compiles when $TYPEDADDRESS
is switched off. On XE7, the program fails to compile irrespective of the setting of $TYPEDADDRESS
.
这是编译器错误吗?或者我使用不正确的语法来获取过程的地址?
Is this a compiler bug? Or am I using incorrect syntax to obtain the address of a procedure?
推荐答案
我相信这是一个编译器错误,并已提交QC报告: QC#127814 。
I believe that this is a compiler bug and have submitted a QC report: QC#127814.
您可以使用以下任一方法:
As a work around you can use either of the following:
- 使用
addr()
而不是@
运算符。 - 演员
@FooVar
或@FooConst
到指针
,例如指针(@FooVar)
。
- Use
addr()
rather than the@
operator. - Cast
@FooVar
or@FooConst
toPointer
, e.g.Pointer(@FooVar)
.
这篇关于格式为什么拒绝从XE4开始的过程地址参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!