compiler-directives

Delphi #IF(DEBUG) equivalent?

ε祈祈猫儿з 提交于 2019-12-03 01:44:43
Is there a Delphi equivalent of the C# #if(DEBUG) compiler directive? Use this: {$IFDEF DEBUG} ... {$ENDIF} PatrickvL Apart from what lassevk said, you can also use a few other methods of compiler-evaluation (since Delphi 6, I believe) : {$IF NOT DECLARED(SOME_SYMBOL)} // Mind you : The NOT above is optional {$ELSE} {$IFEND} To check if the compiler has this feature, use : {$IFDEF CONDITIONALEXPRESSIONS} There are several uses for this. For example, you could check the version of the RTL; From the Delphi help : You can use RTLVersion in $IF expressions to test the runtime library version level

Conditional compile when running in Simulator as opposed to on a device

旧时模样 提交于 2019-12-02 19:05:49
Is there a compiler directive I can use to compile a different line of code when targetting the simulator as opposed to my device. Something like: # IF SIMULATOR [self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; # ELSE [self.imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera]; # END EDIT Direct link to docs. #if TARGET_IPHONE_SIMULATOR [self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; #else [self.imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera]; #endif Update: (Deprecated/Obsolete) This only worked for

Switching between compiler directives in Visual Studio 2019?

ⅰ亾dé卋堺 提交于 2019-12-02 05:57:39
问题 I'm using Visual Studio 2019 with SDK based project, with multiple targets: <TargetFrameworks>netstandard2.0;net45;net46</TargetFrameworks> But when I write conditional code, I see (obviously) some code in gray and some code in regular colors : Question: What settings decide which section will be gray and which will not? Because now, if I want to edit the " NETFULL " section (because I'm multitargeting), it's all gray and I don't have intellisense. How can I tell VS: now let's switch to

C# Compiler Directives

ぐ巨炮叔叔 提交于 2019-12-01 16:08:53
I’m looking at some C# code, and have come across the following statement: #if DEBUG // Do something here #else // Do something else #endif I assumed that DEBUG would be a defined somewhere as follows: #define DEBUG But I’m unable to find such a definition, although the code seems to behave as though it were set. Is DEBUG a special case, and if so, how is it set / unset? On the project, go to Properties -> Build . Under general, you have an option there for defining both DEBUG and TRACE . It is set with the #define directive or in the compiler settings . It is common for DEBUG to be defined in

C# Compiler Directives

自闭症网瘾萝莉.ら 提交于 2019-12-01 15:01:11
问题 I’m looking at some C# code, and have come across the following statement: #if DEBUG // Do something here #else // Do something else #endif I assumed that DEBUG would be a defined somewhere as follows: #define DEBUG But I’m unable to find such a definition, although the code seems to behave as though it were set. Is DEBUG a special case, and if so, how is it set / unset? 回答1: On the project, go to Properties -> Build . Under general, you have an option there for defining both DEBUG and TRACE

Are there any formalized target framework directives?

拈花ヽ惹草 提交于 2019-12-01 10:55:44
问题 I've read Microsoft's article about how to detect target framework, for example : netcoreapp2.2 net47 net58 But there are situations where I don't care about the exact version, but the general framework target : NETCORE .Net Framework But I didn't find such flags. Question: Are there any generalized flags for that ? or better, how can I distinguish between those two without specifying all options? 回答1: Besides the version-specific directives such as NETSTANDARD2_0 , the Target frameworks

Delphi Compiler Directive to Evaluate Arguments in Reverse

随声附和 提交于 2019-12-01 06:06:00
I was really impressed with this delphi two liner using the IFThen function from Math.pas. However, it evaluates the DB.ReturnFieldI first, which is unfortunate because I need to call DB.first to get the first record. DB.RunQuery('select awesomedata1 from awesometable where awesometableid = "great"'); result := IfThen(DB.First = 0, DB.ReturnFieldI('awesomedata1')); (as a pointless clarification, because I've got so many good answers already. I forgot to mention that 0 is the code that DB.First returns if it's got something in it, might not have made sense otherwise) Obviously this isn't such a

How to conditionally reference a DLL based on a compilation symbol?

戏子无情 提交于 2019-11-30 05:12:00
Visual Studio 2013. I have an external DLL which I am referencing like this in the csproj file: <ItemGroup> <Reference Include="NameOfDll"> <HintPath>Path\To\Dll\NameOfDll.dll</HintPath> </Reference> I want this reference to function when a compiler symbol exists and to not function when that compiler symbol does not exist. (To address the first comment, below, let's say the compiler symbol is called Fred.) This question [ Conditional Reference ] made me think I could add an attribute called Condition to the Reference element shown above but I can't work out what value to give that attribute

C# if/then directives for debug vs release

≯℡__Kan透↙ 提交于 2019-11-26 14:49:25
In Solution properties, I have Configuration set to "release" for my one and only project. At the beginning of the main routine, I have this code, and it is showing "Mode=Debug". I also have these two lines at the very top: #define DEBUG #define RELEASE Am I testing the right variable? #if (DEBUG) Console.WriteLine("Mode=Debug"); #elif (RELEASE) Console.WriteLine("Mode=Release"); #endif My goal is to set different defaults for variables based on debug vs release mode. Remove the #define DEBUG in your code. Set preprocessors in the build configuration for that specific build (DEBUG/_DEBUG

C# if/then directives for debug vs release

徘徊边缘 提交于 2019-11-26 05:57:03
问题 In Solution properties, I have Configuration set to \"release\" for my one and only project. At the beginning of the main routine, I have this code, and it is showing \"Mode=Debug\". I also have these two lines at the very top: #define DEBUG #define RELEASE Am I testing the right variable? #if (DEBUG) Console.WriteLine(\"Mode=Debug\"); #elif (RELEASE) Console.WriteLine(\"Mode=Release\"); #endif My goal is to set different defaults for variables based on debug vs release mode. 回答1: Remove the