delphi - 组件是特定类 - 在 BPL 结构中不起作用

我正在将 Delphi 软件从 Delphi 6 (2001) 升级到 Delphi 11 Alexandria。

此软件包含许多 BPL,但此代码无法正常工作。 is command在检查来自 BPL 的组件是否为 TIBQuery 时,不返回 True - 尽管它确实是。

    procedure LoadDLLAndPassDatabaseConnection(const DLLName: string);
    var
      PackageHandle: HMODULE;
      ServiceModule: TMyServiceModule;
      I: Integer;
      Component: TComponent;
    begin
      PackageHandle := LoadPackage(PChar(DLLName));
      ServiceModule := TMyServiceModule(GetProcAddress(hInst,'GetServiceModule'));

      if Assigned(ServiceModule) then
      begin
        for I:=0 to ServiceModule.ComponentCount - 1 do
        begin
          Component := ServiceModule.Components[I];

          // This component is declared in another bpl.
          // It really is an TIBQuery, but the following if never returns True...
          // (Evaluating Component.ClassName results in 'TIBQuery')
          if Component is TIBQuery then
          begin
            // this is never executed...
            TIBQuery(Component).Database := GetDatabase;
          end;
        end;
      end;
    end;

我已经考虑过比较类名,但这对后代不起作用。我们尝试切换项目选项,例如“发出运行时类型信息”,但这没有任何区别。

如何让它工作?

谢谢!

最佳答案

is 运算符不能跨 BPL (DLL) 工作,原因如下:

  • 您正在检查的类在其自己的单元文件中实现。
  • 您构建 BPL,链接单元,然后在 BPL 文件中创建一个 RTTI 部分。
  • 然后,您构建 EXE,链接单元,并在 EXE 文件中创建一个 RTTI 部分。

现在两个模块的类名相同,但是is运算符用来检查相等性的RTTI, 不同,所以运算符返回FALSE!

解决方案:再次检查类名是否相等。

https://stackoverflow.com/questions/73288703/

相关文章:

javascript - 在映射函数中的 .then 内部分配变量

google-cloud-platform - 我无法让 google cloud function

scala - 计算字符串列表中的元音

python - 根据另一个的范围和类别填充 Pandas 列

python - 如何按列导出数据框以分隔 csv 文件?以及如何将不同数据框中的列附加到分离的 c

c - gcc中的 '-Wextra'和 '-pedantic'有什么区别?

reactjs - 使用 React Router 将可选查询参数添加到动态路径

c++ - 子类调用父复制分配而不是移动分配?

javascript - ECMA脚本 : What does `status` mean in S

reactjs - 我可以给 react 查询一个超时(秒或毫秒......)所以在这段时间之后它会