Delphi 我可以强制'const'通过引用传递(也称为'in'参数中缺少的'in'吗)

Delphi 我可以强制'const'通过引用传递(也称为'in'参数中缺少的'in'吗),delphi,pass-by-reference,Delphi,Pass By Reference,德尔福: var:通过引用传递;参数既是输入又是输出。 out:通过引用传递;参数仅输出。 const:经过。。。。。那要看情况了;参数仅为输入。 中的:通过引用传递;参数仅为输入,不会更改,没有“in” 我不介意,但我错过了中的;考虑到下面的代码,有没有更干净的方法来实现这一点 type TFastDiv = record strict private FBuffer: Int64; other fields .... //Must be `var` because `const`

德尔福:

var
:通过引用传递;参数既是输入又是输出。
out
:通过引用传递;参数仅输出。
const
:经过。。。。。那要看情况了;参数仅为输入。
中的
:通过引用传递;参数仅为输入,不会更改,没有“in”

我不介意,但我错过了
中的
;考虑到下面的代码,有没有更干净的方法来实现这一点

type TFastDiv = record 
strict private
  FBuffer: Int64;
  other fields
....

//Must be `var` because `const` would pass a Int64 by value
//                      |||
//                      VVV
function DivideFixedI32(var Buffer: Int64; x: integer): integer;
asm  
  mov  r9,rcx                   
  imul dword ptr[rcx]    // do stuff with the buffer
  ..
  mov     ecx, [r9+4]    // do other stuff with the rest of the buffer  
{将代码更改为
imul ecx;..;shr r9,32;mov ecx,r9d
将允许传递值,但我们假设不能更改代码。}

类运算符TFastDiv.IntDivide(x:integer;常量缓冲区:TFastDiv):integer;
开始
结果:=DivideFixedI32(Int64(@buffer.FBuffer)^),abs(x)) 如果要确保按引用传递,唯一的选择(Delphi XE3之前)是传递一些大的内容。
i、 e.大于sizeof(指针)

类型TFastDiv=记录
严格保密
FBuffer:Int64 较新的编译器版本(从XE3起)支持
[Ref]
装饰器:

procedure Foo(const [Ref] Arg1: Integer; [Ref] const Arg2: Byte);

改编自的示例强调了
[Ref]
可以在
const
关键字之前或之后。

是什么?您真正丢失的是C++ <代码> const MyType和Value<代码> > <代码> >与 Out/<代码>相反,通过引用,但参数不保证更改;是的,一个指针(又名pass_by_reference),在例程中不会被更改。+1非常好。您知道哪些编译器支持此功能吗?桌面编译器会这样做吗?好的,我已经能够在XE5桌面编译器上自己检查这个问题,并且[ref]在那里实现。因此,我希望它在任何地方都能实现。@davidheffernanxe3似乎是第一个(刚刚尝试过),是的,桌面编译器也是如此。
type TFastDiv = record 
strict private
  FBuffer: Int64;   <<-- make sure this is the first member
  other fields
....

function DivideFixedI32(const Buffer: TFastDiv; x: integer): integer;
...
class operator TFastDiv.IntDivide(x:integer; const buffer:TFastDiv):integer;
begin
  Result:= DivideFixedI32(buffer, abs(x));
procedure Foo(const [Ref] Arg1: Integer; [Ref] const Arg2: Byte);