本文介绍了{$ IFOPT A4}?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Delphi 2009(或更早版本)中,如何在代码中检查Align编译选项?
In Delphi 2009 (or older versions), how do you check the "Align" compile option in the code?
IFOPT
指令似乎只能使用纯开关( {$ IFOPT A4}
不编译)。
The IFOPT
directive seems to work only with pure switches ( {$IFOPT A4}
does not compile ).
我找不到等效的常量或这样的定义( {$ IF Align = 4}
等等)
I couldn't find an equivalent constant or such defined ( {$IF Align = 4}
or such )
推荐答案
您可以通过定义具有已知打包规则的记录并使用SizeOf进行检查。在德尔福2009年测试:
You can do this by defining a record with known packing rules and check it using SizeOf. Tested in Delphi 2009:
type
TTestRec = record
A: Byte;
B: Int64;
end;
{$IF SIZEOF(TTestRec) = 9}
{$MESSAGE HINT '$A1'}
{$ELSEIF SIZEOF(TTestRec) = 10}
{$MESSAGE HINT '$A2'}
{$ELSEIF SIZEOF(TTestRec) = 12}
{$MESSAGE HINT '$A4'}
{$ELSEIF SIZEOF(TTestRec) = 16}
{$MESSAGE HINT '$A8'}
{$ELSE}
{$MESSAGE HINT 'Unknown alignment'}
{$IFEND}
这篇关于{$ IFOPT A4}?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!