Inno Setup:遍历Variant类型的数组(来自OleObject) [英] Inno Setup: Iterate through array of type Variant (from OleObject)

查看:317
本文介绍了Inno Setup:遍历Variant类型的数组(来自OleObject)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Inno Setup读写IIS 6元数据库.
我不知道如何访问数组.

I'm trying to read and write to the IIS 6 metabase using Inno Setup.
I can't figure out how to access arrays though.

IIS := CreateOleObject('IISNamespace');
Compr := IIS.GetObject('IIsCompressionScheme', 'localhost/W3SVC/Filters/Compression/deflate');
Arr := Compr.HcScriptFileExtensions;
{ ... [code to iterate and add items] here ... }
Compr.SetInfo();

配置数据库编辑器调用我尝试访问的多字符串"对象类型.

The metabase editor calls the object type I'm trying to access a "multi-string".

VarType(Arr)产生0x200C作为类型(请参见 http://www.jrsoftware.org/ishelp/topic_isxfunc_vartype.htm )

VarType(Arr) yields 0x200C as type (see http://www.jrsoftware.org/ishelp/topic_isxfunc_vartype.htm)

如何使用此类变量? Delphi支持类似

How can I work with such types of variables? Delphi supports something like

for I := VarArrayLowBound(Arr, 1) to VarArrayHighBound(Arr, 1) do

但是Inno Setup没有.还是我必须通过某些OLE/COM函数完全访问数组?

but Inno Setup doesn't. Or do I have to access the array completely via some OLE/COM-functions?

推荐答案

您可以将Variant强制转换为array of string,读取和写入数组,然后进行强制转换:

You can cast the Variant to array of string, read and write the array and then cast back:

var
  VariantArray: Variant;
  Count: Integer;
  ArrayOfStrings: array of string;
  I: Integer;
begin
  { ... }
  VariantArray := Compr.HcScriptFileExtensions;

  { Cast to array }
  ArrayOfStrings := VariantArray;

  { Read the array }
  Count := GetArrayLength(ArrayOfStrings);
  Log(Format('Count = %d', [Count]));

  for I := 0 to Count - 1 do
  begin
    Log(Format('%d: %s', [I, ArrayOfStrings[I]]));
  end;

  { Modify the array (append element) }
  SetArrayLength(ArrayOfStrings, Count + 1);
  ArrayOfStrings[Count] := 'new string';

  { Cast back to the variant }
  VariantArray := ArrayOfStrings;
  ...
end;

仅适用于Unicode版本的Inno Setup.可能是因为 Unicode Inno Setup 是用Delphi 2009而不是Delphi 2和3 ,可能具有更好的Variant支持.另请参见从Ansi升级到Inno Setup的Unicode版本(任何缺点).

Works in Unicode version of Inno Setup only. Probably because the Unicode Inno Setup is compiled with Delphi 2009 instead of Delphi 2 and 3, which likely has better Variant support. See also Upgrading from Ansi to Unicode version of Inno Setup (any disadvantages).

这篇关于Inno Setup:遍历Variant类型的数组(来自OleObject)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆