关于在COM中使用可选参数的研究[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 ocsoft 的 blog

关于在com中使用可选参数的研究

作者:wangzhidong(steven bob)

创作日期:2002-3-27

delphi6中设计com组件方法时,在 parameter flags dialog 中,选择optional选项,即输入参数为可选,现就给出如何实现可选参数实例。 

监测函数

function varisemptyparam(const v: variant): boolean;

begin

  result := (tvardata(v).vtype = varerror) and

            (tvardata(v).verror = $80020004); {disp_e_paramnotfound}

end;

实例

uses comserv, variants, dialogs, sysutils;

procedure toptionalparamsdemo.getparams(const param1: widestring; param2,param3: olevariant; param4: integer);

var

  s2, s3: widestring;

begin

  if varisemptyparam(param2) then

    s2 := ' empty '

  else

    s2 := ' not empty ';

  if varisemptyparam(param3) then

    s3 := ' empty '

  else

    s3 := ' not empty ';

  showmessage(format('param1[%s] param2[%s] param3[%s] param4[%d]',[param1, s2, s3, param4]));

end;

本文关键:VarIsEmptyParam;IDispatch;Variant
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top