* Posts by Paul Marshall

1 publicly visible post • joined 5 Feb 2009

Born Again Delphi

Paul Marshall
Pirate

A few things

Interesting article, but, and I hate to have to say it, you don't know the IDE that well :(

Firstly with the class declaration in Delphi. Once you've typed your function into the class declaration in implements, press ctrl + shift + c. It auto completes the definition in the implements section and then ctrl + shift + down will move you down to it (and pressing up will move you back to the declaration).

Secondly (and here we find out if html tags get through the filter) [b]with[/b] is a useful tool for shortening excessive lines of code. None of the wonderful times where you can't read the line because it's so far of the right hand side that you have to keep scrolling to see what it says. If it's used correctly it's a useful tool, but as ever with tools you don't want to see them in the hands of an amateur.

Next, try finally. Finally is used to execute code that will always be called even if an exception is called. Most people use it for 'cleaning up', but it can be used for logging messages etc of the code pass or just shutting file handles so they don't get left open. Delphi has, built in, a form of garbage collection. Locally declared (to the procedure / function) variables are automatically disposed off when you go out of scope. And then again there's interfaces. I'm sure your aware of how the ref count works on them.

The new keyword is a copy of the reintroduce keyword that overrides the inheritance so that it does complain about visibility etc. If your just overriding a procedure and you don't want it to do the inherited code, leave out the word inherited from the procedure.

Case sensitivity is a major way of screwing up a program. I've seen (having programmed for 14 years now in ASP, ASP.Net, C, C++, C#, Delphi, Java, Informix 4GL, Visual Basic and VB.Net) the same variable being used with slightly different case changes which lead to some wonderful confusion by the guy who wrote it (not me) when he had to fix a bug two weeks later and had forgotten which case meant what.

Lastly your complaint about const. Const is used the same way as #define in C. You define a named constant to represent a value so that if you use it later or change it at a later point, the value is only kept in one place. You don't have to use it, but it makes it a lot easier i.e.

const

LinesPerScreen = 20;

then LinesPerScreen would be used through the code and if we wanted to add more, we just change the one line and not the 50 references throughout the program.

If you wanted you could always declare it as a variable and then initialise it in the initialization section of the unit just to avoid const.

If you want a good change to const, try doing const x : integer = 1; and then using it as an array parameter. That is another thing that needs fixed and it's legacy to Delphi 1.

Apart from that an interesting read.