Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've written about this before, using an example very similar to <a href="https://stackoverflow.com/questions/2051673/how-to-safely-bypass-delphi-error-types-of-formal-and-actual-parameters-must-be/2051769#2051769">Lasse's</a>:</p> <ul> <li><a href="http://www.cs.wisc.edu/~rkennedy/var-identical" rel="nofollow noreferrer">Delphi Q&amp;A: Why must the types of actual and formal var parameters be identical?</a></li> </ul> <p>Unless you're writing an assignment statement to <em>change the value</em> of the input parameter itself, and not just one of its properties, you shouldn't pass a parameter by reference in the first place.</p> <p>If you <em>are</em> writing an assignment statement to change the parameter's value, then the compiler message really is true, and you should heed it.</p> <p>One reason for needing to by-pass the error is when you're writing a function like <a href="http://docwiki.embarcadero.com/VCL/en/Forms.TApplication.CreateForm" rel="nofollow noreferrer"><code>TApplication.CreateForm</code></a>. Its job is to change the input parameter's value, and the type of the new value varies and cannot be determined at compile time. If you're writing such a function, then your only option with Delphi is to use an <a href="http://www.cs.wisc.edu/~rkennedy/untyped" rel="nofollow noreferrer"><em>untyped var</em></a> parameter, and then there is extra burden on both the caller and the receiver to make sure everything goes right. The caller needs to make sure it passes a variable that is capable of holding values of whatever type the function will put in it, and the function needs to make sure it stores a value of a type compatible with what the caller requested.</p> <p>In the case of <code>CreateForm</code>, the caller passes in a class-reference literal and a variable of that class type. The function instantiates the class and stores the reference in the variable.</p> <p>I don't think very highly of either <code>CreateForm</code> or <code>FreeAndNil</code>, largely because of the way their untyped parameters sacrifice type safety in return for comparatively little extra convenience. You haven't shown the implementation of your <code>TotalDestroy</code> function, but I suspect its var parameter will ultimately provide the same low utility as in those other two functions. See my articles on both:</p> <ul> <li><a href="http://www.cs.wisc.edu/~rkennedy/freeandnil" rel="nofollow noreferrer">When should I use <code>FreeAndNil</code>?</a></li> <li><a href="http://www.cs.wisc.edu/~rkennedy/createform" rel="nofollow noreferrer">Why shouldn't I call <code>Application.CreateForm</code>?</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload