如何在 Inno Setup 的 TNewComboBox.Objects 属性中存储 COM 对象?

发布于 2024-09-08 10:20:51 字数 301 浏览 3 评论 0原文

我正在使用 Inno Setup 为我的应用程序创建安装程序。我当前正在使用当前计算机的 IIS 安装上的网站名称填充组合框 (TNewComboBox)。现在我真正想做的是将 COM 对象与字符串一起存储在组合的对象属性中,但即使将 COM 对象包装在 TObject(xxx) 调用中,仍然会出现类型不匹配错误。

我在其他地方读到,TStrings 对象应该有一个 AddObject 方法,但它似乎不存在于 Inno Setup/Pascal Script 中。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖凝香 2024-09-15 10:20:51

不要投射,只需将其包裹在一个对象中即可。

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

不要忘记事后释放它(Delphi 的 tstringlist 缺乏“释放所有”功能)

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)

爱格式化 2024-09-15 10:20:51

Delphi 的 TStrings 类确实有 AddObject方法,但似乎 Inno 的 PascalScript TStrings 包装器没有 。但是,您应该能够像这样设置它:

  Index := Strings.Add('text');
  Strings.Objects[Index] := TObject(xxx);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文