On Emba's website, it is stated that an OUT parameter (does not say which type, so I assume it applies to all types) should not be used for input because its value is "discarded".
Screenshot, to last for eternity :)
""
By discarded, I interpret (even though we are not at the Bible Study hour) that whatever value is present in that variable is thrown away and the variable is zeroed.
Update: from the discussion in the comments I think that the English word "disregarded" or "ignored" would be more accurate.
With an out parameter, however, the initial value of the referenced variable is discarded by the routine it is passed to.
But this simple code shows that the value stored in "i" is not zeroed, but a string "s" is. So the behavious of OUT is not only inconsistent but ALSO undocumented.
TYPE TMyRec = record
i: Integer;
end;
Procedure TestInteger(OUT i: Integer);
Begin
End;
Procedure TestRec(OUT R: TMyRec);
Begin
End;
Procedure TestStr(OUT S: string);
Begin
End;
procedure TfrmTest.btnTestRecClick(Sender: TObject);
begin
VAR MyRecord: TMyRec;
MyRecord.i:= 7;
TestRec(MyRecord);
Memo.Lines.Add('Test rec: '+ IntToStr(MyRecord.i));
end;
procedure TfrmTest.btnTestStrClick(Sender: TObject);
begin
VAR s: string:= 'x';
TestStr(s);
Memo.Lines.Add('Test str: '+ s);
end;
procedure TfrmTest.btnTestIntClick(Sender: TObject);
begin
VAR i: Integer:= 7;
TestInteger(i);
Memo.Lines.Add('Test int: '+ IntToStr(i));
end;
The documentation also says:
But you're not using MyRecord to pass any data to the GetInfo procedure; MyRecord is just a container where you want GetInfo to store the information it generates. The call to GetInfo immediately frees the memory used by MyRecord, before program control passes to the procedure.
But my test code shows that the memory for me record was not zeroed.
So, is the documentation wrong? Is simply the wording wrong? Maybe they meant "ignored" instead of "discarded"? Why is Emba using such confusing words when better alternatives are available?
Update:
Another confirmation that the behavior of the OUT param is not only poorly documented but also inconsistent: The article shows that managed things are always nullified.
https://delphisorcery.blogspot.com/2021/04/out-parameters-are-just-bad-var.html