delphi – [ref]在VCL应用程序中做了什么?

我正在使用Delphi 10 Seattle处理VCL应用程序,并且当我注意到Delphi为Rect参数添加了Ref自定义属性时,通过IDE创建了一个TDBGrid事件处理程序:
procedure TfrmXxx.yyyDrawColumnCell(Sender: TObject;
  const [Ref] Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  //
end;

>何时或为何IDE决定插入此内容
>它在VCL应用程序中有效吗?

更新

这是一个无法重现行为的视频:

解决方法

它在文档中提到:

Constant parameters may be passed to the function by value or by reference,depending on the specific compiler used. To force the compiler to pass a constant parameter by reference,you can use the [Ref] decorator with the const keyword.

Constant Parameters

When or why does the IDE decide to insert this?

IDE永远不会插入它.它只是复制事件处理程序的声明.编写事件处理程序的人将[ref] erence标记放在那里.

Does it have any effect in a VCL app?

是.如果将8字节参数标记为const,它通常会在x64中通过值传递,并在x86中通过引用传递.将它声明为const [ref]将强制它在两种情况下都通过引用传递.在进行内联汇编和多线程代码时非常有用.在引入const [ref]之前,我们被迫使用var而不是const来实现相同的效果.

相关文章

 从网上看到《Delphi API HOOK完全说明》这篇文章,基本上都...
  从网上看到《Delphi API HOOK完全说明》这篇文章,基本上...
ffmpeg 是一套强大的开源的多媒体库 一般都是用 c/c+&#x...
32位CPU所含有的寄存器有:4个数据寄存器(EAX、EBX、ECX和ED...
1 mov dst, src dst是目的操作数,src是源操作数,指令实现的...