这个参数怎麽无类型(10分)

  • 主题发起人 李璋琦
  • 开始时间

李璋琦

Unregistered / Unconfirmed
GUEST, unregistred user!
function SendBuf(var Buf; Count: Integer): Integer;
var buf
这个参数怎麽无类型
 
Buf参数是一个untyped类型的参数,详见下面的Delphi帮助。

You can omit type specifications when declaring var, const, and out parameters.
(Value parameters must be typed.) For example,

procedure TakeAnything(const C);

declares a procedure called TakeAnything that accepts a parameter of any type.
When you call such a routine, you cannot pass it a numeral or untyped numeric
constant.
Within a procedure or function body, untyped parameters are incompatible with
every type. To operate on an untyped parameter, you must cast it. In general,
the compiler cannot verify that operations on untyped parameters are valid.
The following example uses untyped parameters in a function called Equal that
compares a specified number of bytes of any two variables.

function Equal(var Source, Dest; Size: Integer): Boolean;
type
TBytes = array[0..MaxInt - 1] of Byte;
var
N: Integer;
begin
N := 0;
while (N < Size) and (TBytes(Dest)[N] = TBytes(Source)[N]) do
Inc(N);
Equal := N = Size;
end;

Given the declarations
type
TVector = array[1..10] of Integer;
TPoint = record
X, Y: Integer;
end;
var
Vec1, Vec2: TVector;
N: Integer;
P: TPoint;

you could make the following calls to Equal:
Equal(Vec1, Vec2, SizeOf(TVector)) // compare Vec1 to Vec2
Equal(Vec1, Vec2, SizeOf(Integer) * N) // compare first N elements of Vec1 and Vec2
Equal(Vec1[1], Vec1[6], SizeOf(Integer) * 5) // compare first 5 to last 5 elements of Vec1
Equal(Vec1[1], P, 4) // compare Vec1[1] to P.X and Vec1[2] to P.Y
 
懒的看E文,本想有人能解释的....
 

Similar threads

顶部