By Tobias81

2015-12-16 17:02:25 8 Comments

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

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

VarType(Arr) yields 0x200C as type (see

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?


@Martin Prikryl 2015-12-16 18:31:56

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

  VariantArray: Variant;
  Count: Integer;
  ArrayOfStrings: array of string;
  I: Integer;
  { ... }
  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
    Log(Format('%d: %s', [I, ArrayOfStrings[I]]));

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

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

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

@Tobias81 2015-12-17 15:57:38

This throws a "Type Mismatch" exception (ArrayOfStrings := VariantArray).

@Tobias81 2015-12-17 16:29:50

I was using the Ansi version (or more precisely: The developer who started this project). It works well with the Unicode version, so I will port the setup (was already on my agenda anyway). Thanks a lot!

@Martin Prikryl 2015-12-17 16:38:16

Good news. I've added this information to the answer.

@ventsyv 2015-12-16 17:17:50

Inno does not provide full Delphi support, as far as I remember the scripting language is based on Free Pascal.

Try the following:

 for I := 0 to  GetArrayLength(myArray) - 1 do

@Martin Prikryl 2015-12-16 18:32:41

You cannot call GetArrayLength on Variant. You get runtime error "Could not call proc."

@ventsyv 2015-12-16 18:38:57

My bad, I assumed array of string.

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] Updating Inno Setup progress bar from Dephi DLL

2 Answered Questions

[SOLVED] inno setup access violation using ADO

1 Answered Questions

[SOLVED] Inno Setup Run code according to setup type

1 Answered Questions

[SOLVED] Inno Setup Remember selected setup type when Uninstallable=no

1 Answered Questions

[SOLVED] Inno Setup: Working with JSON

1 Answered Questions

[SOLVED] Inno Setup syntax - OR, AND

4 Answered Questions

[SOLVED] Inno Setup for Windows service?

1 Answered Questions

[SOLVED] Conditional DisableProgramGroupPage in Inno Setup

1 Answered Questions

[SOLVED] How to check partition type in inno setup?

1 Answered Questions

[SOLVED] How to catch OleObject exception in Inno Setup?

Sponsored Content