Delphi #IF(DEBUG) equivalent?

后端 未结 4 1758
轮回少年
轮回少年 2021-02-05 07:27

Is there a Delphi equivalent of the C# #if(DEBUG) compiler directive?

4条回答
  •  逝去的感伤
    2021-02-05 08:13

    These control directives are available:

    {$IFDEF}
    {$ELSE}
    {$ENDIF}
    {$IFNDEF} //if *not* defined
    

    and they can be used as shown here:

    procedure TfrmMain.Button1Click(Sender: TObject);
    begin
      {$IFDEF MY_CONDITIONAL}
      ShowMessage('my conditional IS defined!');
      {$ELSE}
      ShowMessage('my conditional is NOT defined!');
      {$ENDIF}
    
      {$IFNDEF MY_CONDITIONAL}
      ShowMessage('My conditional is explicitly NOT defined');
      {$ENDIF}
    end;
    

提交回复
热议问题