[英]Incompatible Types “LongBool” and “Integer”
I needed to compile the source code of Inno Media Player 0.03 which was modified by me to add a Cursor Hiding feature to it using Delphi. 我需要编译Inno Media Player 0.03的源代码,并对其进行了修改,以使用Delphi向其添加“光标隐藏”功能。
I added the code to the source successfully and tried to recompile but the compiler says: 我成功地将代码添加到源代码中,并尝试重新编译,但是编译器说:
[dcc32 Error] MainUnit.pas(154): E2010 Incompatible types: 'LongBool' and 'Integer'. [dcc32错误] MainUnit.pas(154):E2010不兼容的类型:'LongBool'和'Integer'。
What is the problem in this code? 这段代码有什么问题?
The code I added to INNO MEDIA PLAYER: 我添加到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;
I called the IVideoWindow::HideCursor
method on the FVideoWindow
in the TDirectShowPlayer.InitializeVideoWindow
. 我在FVideoWindow
中的TDirectShowPlayer.InitializeVideoWindow
上调用了IVideoWindow::HideCursor
方法。
The OATRUE
Constant is a System.Shortint
and IVideoWindow.HideCursor
is a LongBool
method. OATRUE
常量是System.Shortint
而IVideoWindow.HideCursor
是LongBool
方法。
Are those incompatible types or is my version of Delphi incompatible with this code that I added ? 这些类型不兼容吗?或者我的Delphi版本与我添加的代码不兼容?
On MSDN, IVideoWindow.HideCursor()
is declared as taking a long
as input, not a BOOL
, so it should not be declared as LongBool
in Delphi, it should be Longint
instead. 在MSDN上, IVideoWindow.HideCursor()
被声明为需要很long
输入,而不是BOOL
,因此在Delphi中不应将其声明为LongBool
,而应将其声明为Longint
。 So either fix the declaration, or use a typecast: 因此,要么修正声明,要么使用类型转换:
ErrorCheck(FVideoWindow.HideCursor(BOOL(OATRUE)));
According to DirectShow documentation on IVideoWindow::HideCursor
method signature is: 根据IVideoWindow::HideCursor
上DirectShow文档,方法签名为:
HRESULT HideCursor(
[in] long HideCursor
);
while corresponding signature in Progdigy's Pascal translation is: 而Progdigy的Pascal翻译中相应的签名是:
function HideCursor(HideCursor: LongBool): HResult; stdcall;
So, while your code is absolutely complies to MS specification, you have to deal with incorrect type declaration somehow. 因此,尽管您的代码绝对符合MS规范,但是您必须以某种方式处理错误的类型声明。 You need to typecast your constant to declared type: 您需要将常量类型转换为声明的类型:
ErrorCheck(FVideoWindow.HideCursor(LongBool(OATRUE)));
Note: just passing True
to HideCursor
might also work provided DirectShow isn't sensitive to exact values. 注意:只要DirectShow对精确值不敏感,仅将True
传递给HideCursor
也可能有效。 Use with caution. 请谨慎使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.