【发布时间】:2016-08-18 09:14:03
【问题描述】:
我正在编写一个用于 Delphi 应用程序的 CS .net 包装器,我想从“远程”.net 库中加载图像,因此我不需要在 Delphi 中维护“复制”图像列表。
问题我如何通过 TLB 获取图像列表?
我想我有 3 个选项来实现这个
- 在应用程序启动时,通过 ref 获取 imagelist 并复制到本地 imagelist。这给了我一个 IUnknown 作为 TLB 中的 ref 参数,我可以以某种方式使用它吗?
- 我可以使用字符串/宽字符串或某种类型的流,我认为可以/将被编组为 delphi 类型。
- 我可以将图像列表存储为位图并在启动时将其加载到 delphi 中 - 但谁愿意这样做:)
欢迎提出任何想法/建议。
这是包装方法
public bool LoadImageList(ref ImageList imagelist16, ref ImageList imagelist32, ref String ResMsg)
{
ResMsg = "Imagelist could be loaded: ";
try {
imagelist16 = null;
imagelist32 = null;
if (!_initialized) return false;
imagelist16 = VideoOS.Platform.UI.Util.ImageList;
imagelist32 = VideoOS.Platform.UI.Util.ImageList32;
ResMsg = "Images loaded";
return true;
}
catch (Exception e) {
ResMsg = ResMsg + e.Message;
return false;
}
}
这是 Delphi TLB 单元
function LoadImageList(var imagelist16: IUnknown; var imagelist32: IUnknown;
var ResMsg: WideString; out pRetVal: WordBool): HResult; stdcall;
【问题讨论】:
-
IUnkown 不能直接使用,但可以通过 QueryInterface 用作您需要的接口的访问点。您应该查看如何使用 IUnknown。网上有很多教程,但可能主题太宽泛,无法在这里给出答案。