The direct way to suppress the warning is change the parameter from var to out. Pretty simple but out does more than inhibit the compiler message. It implicitly initialize managed types parameters to nil or add a call FPC_INITIALIZE if the parameter is a record that has at least a field of a managed type. It does not add implicit code to simple types like Integer or class instances (TObject etc).
Although the performance impact is mostly negligible, is extra code anyway. In my case i initialize the parameter explicitly so out would add redundant code. There's an alternative to suppress the message: add the directive {%H-} in front of the variable that is being passed to the procedure. In the example of the previous post would be:
BuildRecArray({%H-}Result);
It can be annoying if the function is called often or the routine is part of a public API, otherwise is fine. At least for me.
Update: out does not generate initialization code for records that contains only fields which type is not automatically managed by the compiler, e.g., Integer.
2 comments:
but the code generated using VAR or OUT is it, not?
if not, would put an example?
The example is in the previous post
Post a Comment