How to conditionally compile a newer Indy feature?

江枫思渺然 提交于 2019-12-07 12:12:41

问题


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.

I've found IdVers.inc, but this file only contains constants - no version conditionals.

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?


回答1:


I think you can get the result you're wanting to achieve using the

{$if declared ...

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.

$if declared works with methods of classes, e.g.

procedure TMyClass.DoSomething;
begin
  {$if declared(TMyClass.Added)}  // Added being a procedure of TMyClass
  Added;
  {$endif}
end;


来源:https://stackoverflow.com/questions/56826276/how-to-conditionally-compile-a-newer-indy-feature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!