The fact is that no matter how careful you are, a program you are currently developing will probably contain some bugs.
Take a look at this piece of code:
if 3 > 5 then;
ShowMessage('3 is greater than 5!!');
It took me a few minutes to figure out why the ShowMessage was always executing!
Do you make mistakes when coding in Delphi? What are your most common errors - "D'Ohs"?
- I can say that I was always saved by the Castalia software. It is unbelievable what this can prevent. I am by no ways affiliated with Castalia, but take a look to that amazing software.
- This used to happen more often, but I 've programmed myself to put the .next inside the block immediately after writing "while not xxx.eof do". It's just like I have programmed myself to immediately attach an attachment to an email when I write something like "Attached is".
for i := 0 to Count
- It seems to happen most often when I process the items of a TStrings or TStringList. When it gets to that last iteration - boom!
if then ... D'Oh
- I wanted to write a simple if then statement, that became a nightmare when I added a semicolon right after then. I took me two hours to see it, in fact after two hours of what I believed to be a magic intervention a collegue told me "weird your semicolon after 'then'" D'Oh :(
- —Guest Shy one
Code completion with CleanupInstance
- I had random AV's in my app for about four years which I could never track down. It turned out that a stringlist I was trying to clear somewhere deep in the bowels of the code had sl.CleanupInstance instead of sl.Clear. I only found it when I created an interface wrapper IStringList which did not expose the CleanupInstance method.
- —Guest G
- I still get caught every now and again by neglecting to prefix a parameter to a procedure that I expect to change with "VAR". On a bad day it might sometimes take me 5-10 minutes of "why isn't this working?" before I have the head-slapping "D'oh" moment. Stephen Posey firstname.lastname@example.org
Forgetting The "Dataset.Next"
- Almost my database development errors are similar to this: While not Table1.EOF do begin List1.Items := Table1.Fields.AsString; //without having Table1.Next here end; All of those lines end on a crash...
Full indenting without begin..end
- I inherited an application, and had to fix one of its errors. Took some time until figured what it is: there was no begin..end after the if..then, but it was properly indented (some 50 statements).
- —Guest Andras
- so many.. my favourite is infinite loop becaue the stop condition is never met in a while or repeat loop.
- —Guest batman
List index out of bounds
- The most common and annoying error i always seem to encounter!
- —Guest Manjari
using with "With" with no mercy!
- sometimes I have code like: object1.property1 := '1'; object2.property2 := '2'; property3 := '3'; object4.property4 := '4'; So I happily (and stupidly ) change it to: with object1 do begin property1 := '1'; property2 := '2'; property3 := '3'; property4 := '4' end; Sometimes, property3 exists in object1 and Self (which was the intended meaning) and after introducing the "with" I have introduced a subtle bug :@. Always check before introducing a "with", and keep´em short! Be careful when nesting´em
- —Guest Alvaro Castiello
- I sometimes get in a hurry when traversing a database and might use something like While not database.eof do begin Do something here end; All the while forgetting to put the Database.next in the loop... OOPS!
- —Guest Robert Smith
i for idiot
- I spent half a day trying to figure out why one of my loops kept blowing up. I've done a million and never had a problem, what the heck, just couldn't see it..... FINALLY realized I was defining i as a WORD and the loop was starting as a negative number. I was trying to save space by using Word instead of Integer...NEVER AGAIN.
- Once I have been confused when my software to find customers with birthday in given interval found nothing.. )) A little debug, type match check, etc, I realized that there is really no one who was born in last few days! :-)))) (Comparing dates with an year portion) D'ooooh! )
- —Guest Mch
- I was tired while coding an application, it was an EXTREMELY long one. I compiled it for the first time, and realised I'd forgotten every single semi-colon. It took a lot of replacing.
- —Guest Joshuzzz