当他们期望 NativeUInt 时,我应该如何将负值传递给 SendMessage 和 Perform? [英] How should I pass negative values to SendMessage and Perform when they expect a NativeUInt?

查看:23
本文介绍了当他们期望 NativeUInt 时,我应该如何将负值传递给 SendMessage 和 Perform?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你有这样的代码:

Result.X := ACustomMemo.Perform(EM_LINEFROMCHAR, -1, 0); 

Windows API 声称-1"是一个有效值,使其返回活动行.

The Windows API claims "-1" is a valid value that makes it it return the active line.

但是,Delphi 将其定义为 NaiveUInt 并在我尝试传递 -1 时抱怨.

However, Delphi has this defined as NaiveUInt and complains if I try to pass -1.

最干净的解决方案是什么?铸造?

What is the cleanest solution to this? Casting?

推荐答案

将 -1 值强制转换为 WPARAM 是处理这种情况的正确方法.

Casting the -1 value to WPARAM is the proper way to handle this case.

 Result.X := ACustomMemo.Perform(EM_LINEFROMCHAR, WPARAM(-1), LPARAM(0));

顺便说一句,WPARAM 类型的 delphi NativeUint 定义是正确的,因为是 x86 上的无符号 32 位和 x64 上的无符号 64 位.

btw, the delphi NativeUint definition for the WPARAM type is correct, because is a unsigned 32-bit on x86 and unsigned 64-bit on x64.

这篇关于当他们期望 NativeUInt 时,我应该如何将负值传递给 SendMessage 和 Perform?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆