正如你所能想到的,由于Array of const 形式的参数可以传递不同类型的参数,使得接收这些参数的函数和过程工作起来比较困难。作为一个例子,下面的代码是WhatHaveIGot()过程的实现,在这个例子中依次判断每一个数据的类型,并在屏幕上显示数据的序号和类型:
procedure WhatHaveIGot(A : Array of Const); var i : integer; TypeStr : string; begin for i := Low(A) to High(A)do begin Case A[i].VType of VtInteger : TypeStr := 'Integer'; VtBoolean : TypeStr := 'Boolean'; VtChar : TypeStr := 'Char'; VtExtended : Typestr := 'Extended'; VtString : TypeStr := 'String'; Vtpointer : TypeStr := 'Pointer'; VtPChar : TypeStr := 'PChar'; Vtobject : TypeStr := 'Object'; Vtclass : TypeStr := 'Class'; VtwideChar : TypeStr := 'WideChar'; VtPWideChar : TypeStr := 'PWideChar'; VtAnsiString : TypeStr := 'AnsiString'; VtCurrency : TypeStr := 'Currency'; VtVariant : TypeStr := 'Variant'; VtInterface : TypeStr := 'Interface'; VtwideString : TypeStr := 'WideString'; VtInt64 : TypeStr := 'Int64'; end; ShowMessage(ForMat('Array item %d is a a %s',[i, TypeStr])); end; end;