如何有条件地编译较新的Indy功能? [英] How to conditionally compile a newer Indy feature?
问题描述
我已经找到有关如何在运行时检查Indy版本的此答案不同的方式。但是,我正在寻找如何在编译时使用条件语句检查Indy版本。较新版本的Indy中有一项功能,我希望我的开源项目能够使用此功能。但是我需要有条件地对其进行编译。
I've already found this answer on how to check the Indy version at run-time, and there are multiple different ways. However I'm looking how to use conditionals to check the Indy version at compile-time. There's a feature in newer versions of Indy, and I want my open-source project to use this feature if it's available. But I need to conditionally compile it.
我发现 IdVers.inc
,但是此文件仅包含常量-没有版本条件。
I've found IdVers.inc
, but this file only contains constants - no version conditionals.
更具体地说, TIdHTTP
具有属性 HTTPOptions
,其中有一个新选择 hoWantProtocolErrorContent
。如果可用,我想使用它。
More specifically, the TIdHTTP
has a property HTTPOptions
which has a new choice hoWantProtocolErrorContent
. If this is available, I'd like to use it.
如果可用,如何有条件地使用此选项?
How can I conditionally use this option if it's available?
推荐答案
我认为您可以使用$
I think you can get the result you're wanting to achieve using the
{$if declared ...
构造。在rtl的SysInit.Pas中有一个使用示例:
construct. There is an example of its usage in SysInit.Pas in the rtl:
function GetTlsSize: Integer;
{$IF defined(POSIX) and defined(CPUX86) and (not defined(EXTERNALLINKER))}
asm
// Use assembler code not to include PIC base gain
MOV EAX, offset TlsLast
end;
{$ELSE}
begin
Result := NativeInt(@TlsLast);
{$IF DECLARED(TlsStart)}
Result := Result - NativeInt(@TlsStart);
{$ENDIF}
[...]
As well as the article I mentioned in a comment, $If Declared, there is also this in the D2009 online help.
$如果已声明
可使用类方法,例如
procedure TMyClass.DoSomething;
begin
{$if declared(TMyClass.Added)} // Added being a procedure of TMyClass
Added;
{$endif}
end;
这篇关于如何有条件地编译较新的Indy功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!