5.非強類型參數
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;
//調用
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
6.字符串參數
//這樣做是錯的
procedure Check(S: string[20]); // syntax error
//這樣做是對的
type TString20 = string[20];
procedure Check(S: TString20);
//OpenString
procedure Check(S: OpenString);