Delphi. Excessive type-bondage.

[prev] [thread] [next] [lurker] [Date index for 2006/08/25]

From: Phil!Gregory
Subject: Delphi. Excessive type-bondage.
Date: 22:08 on 25 Aug 2006
Allow me to quote from the Delphi help file:

  For a variable parameter, the actual argument must be of the exact type
  of the formal parameter. 

    procedure SwapBytes(var B1, B2: Byte);
    var
      Temp: Byte;
    begin
      Temp := B1; B1 := B2; B2 := Temp;
    end;
    
    var
      C1, C2: 0..255;     (*Similar to a byte, but NOT identical*)
    begin
      SwapBytes(C1,C2);   (*<-- Error message here*)
    end.

  Arguments C1 and C2 are not acceptable to SwapBytes, *although they have
  the exact memory representation and range that a Byte has*.  [Emphasis
  mine.]

Oh, and for the case where I specifically ran into this, typecasting won't
help.  Apparently when you typecast a variable, the result looks like a
constant to the compiler so you can't pass it as a variable parameter
(pass by reference).

-- 
...computer contrarian of the first order... / http://aperiodic.net/phil/
PGP: 026A27F2  print: D200 5BDB FC4B B24A 9248  9F7A 4322 2D22 026A 27F2
--- --
> This made me wonder, suddenly: can telnet be written in perl?
Of course it can be written in Perl.  Now if you'd said nroff,
that would be more challenging...
                       -- Larry Wall
---- --- --

Generated at 18:01 on 30 Aug 2006 by mariachi 0.52