Delphi Handbooks Collection


Delphi XE Handbook


Delphi 2010 Handbook


October 24, 2008

Six Hidden Features of Delphi 2009

You've heard about Unicode, generics, and the like... but there is way more in Delphi 2009, including a few hidden gems. Here is a random selection.

You've heard about Unicode, generics, and the like... but there is way more in Delphi 2009, including a few hidden (or not commonly mentioned) gems. Here is a random selection. I'm not 100% percent sure they are the 5 best, and all five hidden, but you get the idea. And they are not in any order:

  • Exit with a value (I know, this was blogged about, but worth repeating)
  • InnerException (that is you raise an exception while handling one... and both exception objects are kept around)
  • TTextReader interface for streams (and strings), this is so nice you won't care about StringBuilder
  • You can change the internal classes used by any DataSet by changing a global variable holding a class (FieldDefs, IndexDefs, Params... and many more)
  • TObject.ToString and the other new methods of the TObject class
  • commented deprecated (that is, deprecated with a string indicating an extra compiler hint, too bad it is not used much by the VCL)

(this was hinted by me repeating there are many goodies in the product over the two days seminar on Delphi 2009 I just did.) I could easily add 5 more covering VCL controls (aligned edits, text hints, balloon help, buttons with images, grouping in listview) but they are not so "hidden". Anything else you want to share? I'm pretty sure this list is far from complete... and there are others I had to leave out but would be worth adding.





 

7 Comments

Six Hidden Features of Delphi 2009 

The new support for PNG is very nice hidden feature too :)
Comment by Mohammed Nasman [http://www.mnasman.com/blog] on October 24, 22:05

Six Hidden Features of Delphi 2009 

I differed the RTL/VCL between 2006 and 2009, and
here's most of the things I found.  Some of these may
have been implemented in 2007's VCL, but I didn't have
that handy to check.

TStringList has a new property: OwnsObjects.  There's
also an overloaded constructor that takes a Boolean
parameter to set it.

There's a TByteStream class that inherits from
TMemoryStream.

TThread has some new properties: Finished: Boolean,
ExternalThread: Boolean and class property
CurrentThread: TThread.  And some Anonymous Method
support too.

There's some implementations of TTextReader and
TTextWriter in TStringReader, TStringWriter,
TStreamReader, and TStreamWriter.  The TStream
implementations are very interesting because they
finally layer Buffering and ReadLine/WriteLine support
onto a stream.  Sure, everybody and their brother has
their own implementation, but being baked into the VCL
makes it official.

IncHour, IncMinute, IncSecond, and IncMilliSecond now
subtract your delta from the passed in value if value
is less than 0.  In other words, a positive delta will
always move the time away from 0.  IncDay, IncWeek,
and IncYear do not do this.

InRange is inlined.

RoundTo and SimpleRoundTo now operate on Extended
instead of Double.

THandleObject has a WaitForMultiple method.  There's
also new TSemaphore, TConditionVariableMutex, and
TConditionVariableCS objects.

TObject gained an Equals method.

TObject also has new methods in GetHashCode and
UnitName.  (I'm guessing those are mostly for runtime
package or RTTI?)

There's a TMonitor record in System.pas with some
class methods.  It looks like it implements some kind
of spinlocking around a TObject.  I haven't had a
chance to disect it though.

A new MoveChars procedure.  Works exactly like Move
only it automatically multiplies Count by SizeOf(Char).

New UIntToStr functions.  Overloaded for Cardinals and
Int64s.

Messages.pas now has SendTextmessage,
SendStructMessage, SendGetStructMessage,
SendGetIntMessage.  This looks like it's done for .NET
compatibility.

THeaderSection got some new properties: CheckBox,
Checked, and FixedWidth.  THeaderSections got them as
well.

I didn't dig into the VCL changes yet, there's /lots/
of changes in it, and I haven't had the time to sort
through them all to see what I didn't already know about.
Comment by Anthony Frazier on October 24, 22:11

Six Hidden Features of Delphi 2009 

I noticed that in D2009 it is legal to write something
like 
type TMyEnum = (enOne, enTwo);
…
var
  e: TMyEnum;
begin
  e:= TMyEnum.enOne
end;

This syntax looks pretty much like that of C#, but I
consider it to be rather convenient. It must be
especially useful when you encapsulate your enum type
in a class declaration.
Comment by ua.Skywalker [http://www.subtlesoft.com] on October 24, 22:36

GetHashCode 

I think TObject.GetHashCode is worth mentioning, 
although it is interesting that it defaults to Integer(Self), but I guess that is unique for all 
objects in memory right now.  

Would have expected TPersistant descendants, or at 
some point, to use a hash of the streamed data. . . .  
Guess it is just a different way of thinking about a 
hash. . . . 
Comment by Jim McKeeth [http://www.Delphi.org/] on October 24, 23:08

Six Hidden Features of Delphi 2009 

Pls mention about the new functionality for database 
area next.

I havent bought delphi2009 yet but as long as I saw 
help files, new types for TFieldType seems got 
introduced in delphi2009 like TLongwordField, 
TExtendedField and so on.

TStringFiled is for UnicodeString?
TWideStringField is for what?



Comment by John on October 25, 04:00

Six Hidden Features of Delphi 2009 

Thank you for the info, hoping it will be easier to 
find informations about the new features in the help 
system <g>

I am a bit surprised that after Delphi 2009 launch 
CodeGear people didn't take the time to talk about 
them extensively. But Bauer, who is anyway talking 
about advanced implementations, there are only 
fragments or hints about them, or nothing (never read 
anything about the new dataset feature, or the 
improved streams interfaces).
While the most important thing looks to be to raise 
the Delphi position in the Tiobe index! Ok, some of 
them are around the world at various conferences, but 
people attending conferences are just a part of the 
developer community.

Maybe talking and writing a little more about new 
features and how they could help developer would 
improve the ranking too (and boost sales).
Comment by Luigi D. Sandon on October 25, 17:25

Six Hidden Features of Delphi 2009 

Hi Luigi D. Sandon,

A read what you've wrote and I support your opinion.
One more vote for 
- more talking (video chat) and writing (exemple of
code, the use).
- more about ER design system (write one model,
connect to every database???)

Best Regards,


Léo.
Comment by Leonardo M. Neto - from Brazil and Delphi 3 [http://www.mozachi.com.br] on November 22, 04:50


Post Your Comment

Click here for posting your feedback to this blog.

There are currently 0 pending (unapproved) messages.