【问题标题】:Incompatible Types "LongBool" and "Integer"不兼容的类型“LongBool”和“Integer”
【发布时间】:2016-06-28 04:36:00
【问题描述】:

我需要编译 Inno Media Player 0.03 的源代码,我使用 Delphi 对其进行了修改以添加光标隐藏功能。

我成功将代码添加到源代码并尝试重新编译但编译器显示:

[dcc32 错误] MainUnit.pas(154): E2010 不兼容的类型:'LongBool' 和 'Integer'。

这段代码有什么问题?

我添加到INNO MEDIA PLAYER的代码:

const
  OATRUE = -1;

procedure TDirectShowPlayer.InitializeVideoWindow(WindowHandle: HWND; var Width,
  Height: Integer);
begin
  ErrorCheck(FGraphBuilder.QueryInterface(IVideoWindow, FVideoWindow));
  ErrorCheck(FVideoWindow.HideCursor(OATRUE));     **<<<ERROR IS HERE<<<**
  ...
end;

我在TDirectShowPlayer.InitializeVideoWindow中的FVideoWindow上调用了IVideoWindow::HideCursor方法。

OATRUE 常量是 System.ShortintIVideoWindow.HideCursorLongBool 方法。

是这些不兼容的类型还是我的 Delphi 版本与我添加的代码不兼容?

【问题讨论】:

    标签: delphi


    【解决方案1】:

    在 MSDN 上,IVideoWindow.HideCursor() 被声明为将 long 作为输入,而不是 BOOL,因此在 Delphi 中不应将其声明为 LongBool,而应改为 Longint。所以要么修复声明,要么使用类型转换:

    ErrorCheck(FVideoWindow.HideCursor(BOOL(OATRUE)));
    

    【讨论】:

      【解决方案2】:

      根据DirectShow documentation on IVideoWindow::HideCursor方法签名为:

      HRESULT HideCursor(
        [in] long HideCursor
      );
      

      而 Progdigy 的 Pascal 翻译中对应的签名是:

      function HideCursor(HideCursor: LongBool): HResult; stdcall;
      

      因此,虽然您的代码绝对符合 MS 规范,但您必须以某种方式处理不正确的类型声明。您需要将常量类型转换为声明的类型:

      ErrorCheck(FVideoWindow.HideCursor(LongBool(OATRUE)));
      

      注意:只要 DirectShow 对精确值不敏感,只需将 True 传递给 HideCursor 也可能有效。谨慎使用。

      【讨论】:

      • 现在错误消失了,我编译成功了。非常感谢。但我很惊讶为什么我的鼠标光标仍然没有隐藏在视频中?
      • 你应该选择一个正确的答案,即使他们都说同样的话。您的可见光标是问题中没有真正涉及的另一个问题。 :)
      猜你喜欢
      • 2012-04-26
      • 2018-10-28
      • 2023-03-10
      • 1970-01-01
      • 2018-05-28
      • 2017-03-27
      • 2014-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多