views:

99

answers:

2

I'm using Inno Setup to create an installer for my application. I'm currently filling a combobox (TNewComboBox) with the names of the Web sites on the current machine's IIS install. Now what I really want to do is store the COM object alongside the string in the objects property of the combo but keep getting type mismatch errors, even when wrapping the COM object in a TObject(xxx) call.

I've read in other places that the TStrings object should have an AddObject method but it doesn't seem to be present in Inno Setup/Pascal Script.

+1  A: 

Delphi's TStrings class does have AddObject method but it seems that Inno's PascalScript TStrings wrapper doesn't. However, you should be able to set it like this:

  Index := Strings.Add('text');
  Strings.Objects[Index] := TObject(xxx);
TOndrej
Unfortunately that still errors, I think when it tries to cast my variant to an object. It works fine when I put an object in there (such as TObject.Create() for example), so I guess the question is how to I create an object from a variant and can I get the variant back again later?
Chris Meek
You could also try to use your own array of Variants (I assume this is possible in PascalScript) to store your COM Objects. Then each combobox item would have a corresponding COM object and you don't need to use the Objects property.
TOndrej
+3  A: 

Do not cast, just wrap it in an object.

 Type
     TMyObjectForStringList = class 
                                fCOMThingy : variant;   // or ole variant
                                constructor create(comthingy:variant); 
                               end;

  constructor TMyObjectForStringList.Create(comthingy:variant);
  begin
    fcomthingy:=comthingy;
  end;

 myStringList.addobject(astring,TMyObjectForStringList.Create(avariant));

Do not forget to free it afterwards (Delphi's tstringlist lacks "deallocate all" functionality)

Marco van de Voort