正如你所能想到的,由于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;

相关文章:

  • 2021-08-18
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2021-10-23
猜你喜欢
  • 2021-11-17
  • 2022-02-07
  • 2023-04-08
  • 2022-12-23
  • 2021-09-08
相关资源
相似解决方案