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

后端 未结 2 2030
长发绾君心
长发绾君心 2020-12-18 16:15

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.



        
相关标签:
2条回答
  • 2020-12-18 16:46

    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
      begin
         //stuff
      end;   
    
    0 讨论(0)
  • 2020-12-18 16:53

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

    0 讨论(0)
提交回复
热议问题