I'm working on a VCL application with Delphi 10 Seattle, and created a TDBGrid event handler via the IDE when I noticed that Delphi added a Ref
custom attribute for the Rect
argument:
procedure TfrmXxx.yyyDrawColumnCell(Sender: TObject;
const [Ref] Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
//
end;
update
Here's a video for those who cannot reproduce the behavior:
It is mentioned in the docs:
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.
See Constant Parameters
When or why does the IDE decide to insert this?
The IDE never inserts this. It just copies the declaration of the event handler. Whoever wrote the event handler put the pass by[ref]
erence marker in there.
Does it have any effect in a VCL app?
Yes.
If you mark a 8 byte parameter as const it will normally get passed by value in x64 and passed by reference in x86.
Declaring it as const [ref]
will force it to be passed by reference in both cases.
It is very useful when doing inline assembly and in multi-threaded code.
Before const [ref]
was introduced we were forced to use var
instead of const
to achieve the same effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With