【发布时间】:2021-08-29 09:50:28
【问题描述】:
尝试将整数转换为 32 个布尔值的压缩记录。
TUserRightsRecord = packed record
r1:boolean;
.
.
end;
然而,我找不到将变量转换为打包记录的函数,因为直接赋值不起作用。
- 什么函数将变量(或至少整数)转换为相同字节大小的打包记录?
【问题讨论】:
-
SizeOf(Boolean)不是 1/8,而是 1:Boolean是一个字节(8 位)。无论如何:你为什么需要这个?为什么不像其他人一样使用按位运算? -
你能举个例子给我一些想法吗?你有什么建议?
-
const HasScreen = 1; HasSound = 2; HasKeyboard = 4; HasMouse = 8; HasInternet = 16; var ComputerProperties: Integer; // Test a bit if ComputerProperties and HasInternet = 0 then ShowMessage('You need an Internet connection.'); // Set a bit Computer := Computer or HasInternet; // Clear a bit Computer := Computer and not HasInternet;但在 Delphi 中,您通常使用 sets 代替。 -
希望得到更优雅的东西,比如 c++ 中 struct 的 typedef union :'|
-
@YordanYanakiev to hoop 与 to hope。还要检查How to simulate bit-fields in Delphi records?
标签: delphi