Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

ole - Inno Setup: Iterate through array of type Variant (from OleObject)

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) yields 0x200C as type (see http://www.jrsoftware.org/ishelp/topic_isxfunc_vartype.htm)

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

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...