I use Delphi 10.4 and build 32 and 64 Bit applications. I noticed that the initialization of boolean variables depends on the type of application (32 bit and 64 bit). I build a simple app. Here is my code: procedure TForm1.Button1Click(Sender: TObject); var   value: boolean; begin   ShowMessage(value.ToString); end;  In 32 bit value is true and in 64 bit value is false. Is this a normal behaviour? And how can I change it?
4630
I'm new to Delphi, and I've been running some tests to see what object variables and stack variables are initialized to by default:  TInstanceVariables = class   fBoolean: boolean; // always starts off as false   fInteger: integer; // always starts off as zero   fObject: TObject; // always starts off as nil end;   This is the behaviour I'm used to from other languages, but I'm wondering if it's safe to rely on it in Delphi?  For example, I'm wondering if it might depend on a compiler setting, or perhaps work differently on different machines.  Is it normal to rely on default initialized values for objects, or do you explicitly set all instance variables in the constructor?  As for stack (procedure-level) variables, my tests are showing that unitialized booleans are true, unitialized integers are 2129993264, and uninialized objects are just invalid pointers (i.e. not nil).  I'm guessing the norm is to always set procedure-level variables before accessing them?
21733
EmployeeNumber = string.IsNullOrEmpty(employeeNumberTextBox.Text)     ? null     : Convert.ToInt32(employeeNumberTextBox.Text),  I often find myself wanting to do things like this (EmployeeNumber is a Nullable&lt;int&gt; as it's a property on a LINQ-to-SQL dbml object where the column allows NULL values).  Unfortunately, the compiler feels that  There is no implicit conversion between 'null' and 'int'  even though both types would be valid in an assignment operation to a nullable int on their own. Using the null coalescing operator is not an option as far as I can see because of the inline conversion that needs to happen on the .Text string if it's not null. As far as I know the only way to do this is to use an if statement and/or assign it in two steps.  In this particular case I find that very frustrating because I wanted to use the object initializer syntax and this assignment would be in the initialization block... Does anyone know a more elegant solution?
26836
Not to long ago, someone told me that long are not 64 bits on 64 bit machines and I should always use int. This did not make sense to me. I have seen docs (such as the one on Apple's official site) say that long are indeed 64 bits when compiling for a 64-bit CPU. I looked up what it was on 64-bit Windows and found         Windows: long and int remain 32-bit in length, and special new data types   are defined for 64-bit integers.      (from )  What should I use? Should I define something like uw, sw ((un)signed width) as a long if not on Windows, and otherwise do a check on the target CPU bitsize?
79610
an example code what I try to do will surely do better than my english:  public bool IsNumericValueInBounds (string value, Type numericType) {   double d = double.NaN;         bool inBounds = (bool)numericType.GetMethod ("TryParse").Invoke (null, new object[] { value, d });    return inBounds; }   Unfortunately the TryParse method needs an out parameter so this doesn't work. any ideas how to solve this?  (ps.: would'nt this be a nice example for duck typing? - because i know every numericType has an "TryParse" or I am mistaken?)
7865
Is there any class in the .NET framework that can read/write standard .ini files:  [Section] &lt;keyname&gt;=&lt;value&gt; ...   Delphi has the TIniFile component and I want to know if there is anything similar for C#?
103793
I have a generic class that should allow any type, primitive or otherwise. The only problem with this is using default(T). When you call default on a value type or a string, it initializes it to a reasonable value (such as empty string). When you call default(T) on an object, it returns null. For various reasons we need to ensure that if it is not a primitive type, then we will have a default instance of the type, not null. Here is attempt 1:  T createDefault() {     if(typeof(T).IsValueType)     {         return default(T);     }     else     {         return Activator.CreateInstance&lt;T&gt;();     } }   Problem - string is not a value type, but it does not have a parameterless constructor. So, the current solution is:  T createDefault() {     if(typeof(T).IsValueType || typeof(T).FullName == "System.String")     {         return default(T);     }     else     {         return Activator.CreateInstance&lt;T&gt;();     } }   But this feels like a kludge. Is there a nicer way to handle the string case?
59230
Is there an easy way to check if a binary is 32 or 64 bit on Windows? I need to check before I move the program to a 32bit machine and experience a spectacular failure.
3450
I've always wondered this - why can't you declare variables after a case label in a switch statement?  In C++ you can declare variables pretty much anywhere (and declaring them close to first use is obviously a good thing) but the following still won't work:  switch (val)   {   case VAL:     // This won't work   int newVal = 42;     break; case ANOTHER_VAL:     ...   break; }     The above gives me the following error (MSC):     initialization of 'newVal' is skipped by 'case' label   This seems to be a limitation in other languages too.  Why is this such a problem?
32837
int temp = 0x5E; // in binary 0b1011110.   Is there such a way to check if bit 3 in temp is 1 or 0 without bit shifting and masking.  Just want to know if there is some built in function for this, or am I forced to write one myself.
115814
I'm planning to add XML support to application, but I'm not familiar with XML programming in Delphi. Basically I need to create objects based on XML nodes and generate XML file based on objects.  Which XML component library I should use? Are there any good tutorials for XML with Delphi?
4029
uint color;  bool parsedhex = uint.TryParse(TextBox1.Text, out color);  //where Text is of the form 0xFF0000 if(parsedhex)    //...   doesn't work. What am i doing wrong?
54872
I'm generating a level, and I have an optional delay to show the steps level generation one by one.  If my generationDelay boolean is true, I want to use StartCoroutine to spread the generation out over time. If it's false, I want to call the same method but without StartCoroutine.  The problem is that the method is type IEnumerator.  I can make two methods one type of IEnumerator and one not. But I wonder if there is a way to use one method.  In the first script top i did:  public bool generationDelay = false;   Then in a method:  private void BeginGame()     {         mazeInstance = Instantiate(mazePrefab) as Maze;          if (generationDelay == true)         {             StartCoroutine(mazeInstance.Generate(generationDelay));         }         else         {             mazeInstance.Generate(generationDelay);         }     }   Then the other script where the method Generate is: In the top:  public float generationStepDelay = 0.01f;   Then the method Generate:  public IEnumerator Generate (bool generationDelay) {          if (generationDelay == true)             WaitForSeconds delay = new WaitForSeconds(generationStepDelay);         cells = new MazeCell[size.x, size.z];         List&lt;MazeCell&gt; activeCells = new List&lt;MazeCell&gt;();         DoFirstGenerationStep(activeCells);         while (activeCells.Count &gt; 0) {             yield return delay;             DoNextGenerationStep(activeCells);         }     }   I'm getting an error on the line:   WaitForSeconds delay = new WaitForSeconds(generationStepDelay);      "Embedded statement cannot be a declaration or labeled statement"   And an error on the line:  yield return delay;      "The name 'delay' does not exist in the current context"   The reason I want to use a bool variable is that when i'm using StartCoroutine it's kind of slow, even if I change the value of generationStepDelay to 0 it's kind of slow. And if I'm not using StartCoroutine and not using the Generate method as IEnumerator it will work fast.  So i wonder what should I do and how?
99569
Is there a way to write binary literals in C#, like prefixing hexadecimal with 0x? 0b doesn't work.  If not, what is an easy way to do it? Some kind of string conversion?
14488
I saw this in , in reference to shortcomings of the Java spec:  There are more shortcomings and this is a subtle topic. Check  out: public class methodOverloading{      public static void hello(Integer x){           System.out.println(&quot;Integer&quot;);      }       public static void hello(long x){           System.out.println(&quot;long&quot;);      }       public static void main(String[] args){          int i = 5;          hello(i);      } }  Here &quot;long&quot; would be printed (haven't checked it myself), because the compiler chooses widening over auto-boxing. Be careful when using auto-boxing or don't use it at all!  Are we sure that this is actually an example of widening instead of autoboxing, or is it something else entirely? On my initial scanning, I would agree with the statement that the output would be &quot;long&quot; on the basis of i being declared as a primitive and not an object.  However, if you changed hello(long x)  to hello(Long x)  the output would print &quot;Integer&quot; What's really going on here?  I know nothing about the compilers/bytecode interpreters for java...
115229
We use the so-called zero conditional when the result of the condition is always true.  What about following situation. Let's say that we have a poorly written application. :) and I complain that it simply does not work. It is always true for this version of application.  Zero conditional sounds good to me. Is it wrong to use first conditional here?   "if I press a button it crashes." "if I press a button it will crash."   thanks!
23330
I am trying to adapt an existing code to a 64 bit machine. The main problem is that in one function, the previous coder uses a void* argument that is converted into suitable type in the function itself. A short example:  void function(MESSAGE_ID id, void* param) {     if(id == FOO) {         int real_param = (int)param;         // ...     } }   Of course, on a 64 bit machine, I get the error:  error: cast from 'void*' to 'int' loses precision   I would like to correct this so that it still works on a 32 bit machine and as cleanly as possible. Any idea ?
49999
When writing a switch statement, there appears to be two limitations on what you can switch on in case statements.  For example (and yes, I know, if you're doing this sort of thing it probably means your  (OO) architecture is iffy - this is just a contrived example!),    Type t = typeof(int);    switch (t) {      case typeof(int):       Console.WriteLine("int!");       break;      case typeof(string):       Console.WriteLine("string!");       break;      default:       Console.WriteLine("unknown!");       break;   }   Here the switch() statement fails with 'A value of an integral type expected' and the case statements fail with 'A constant value is expected'.  Why are these restrictions in place, and what is the underlying justification? I don't see any reason why the switch statement has to succumb to static analysis only, and why the value being switched on has to be integral (that is,  primitive). What is the justification?