我正在将 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) 工作,原因如下:
现在两个模块的类名
相同,但是is
运算符用来检查相等性的RTTI, 不同,所以运算符返回FALSE!
解决方案:再次检查类名是否相等。
https://stackoverflow.com/questions/73288703/
相关文章:
javascript - 在映射函数中的 .then 内部分配变量
google-cloud-platform - 我无法让 google cloud function
python - 根据另一个的范围和类别填充 Pandas 列
python - 如何按列导出数据框以分隔 csv 文件?以及如何将不同数据框中的列附加到分离的 c
c - gcc中的 '-Wextra'和 '-pedantic'有什么区别?
reactjs - 使用 React Router 将可选查询参数添加到动态路径