加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 04:35:15 所属栏目:大数据 来源:网络整理
导读:我正在使用Delphi 10 Seattle处理VCL应用程序,并且当我注意到Delphi为Rect参数添加了Ref自定义属性时,通过IDE创建了一个TDBGrid事件处理程序: procedure TfrmXxx.yyyDrawColumnCell(Sender: TObject; const [Ref] Rect: TRect; DataCol: Integer; Column: T
我正在使用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来实现相同的效果.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读