views:

776

answers:

5

I've been programming in Delphi for a little over two years now, and I've only got maybe 5 custom templates, I feel as though I should have more.

If anyone has any particularly useful ones it would be great to have a nice repository of them here on stackoverflow.

I don't care whether you use the Delphi 2009 syntax or Delphi 7, but if the code you'd be generating only works on a particular version, please mention that.

+4  A: 

This one is pretty handy because it always shows up first when I hit ctrl-j (so my shortcut is ctrl-j enter)


Name:
//*
Description:
Comment Line
Code:

//******************************************************************************  

I use it to start documentation around methods. It sure beats hitting '*' 78 times.

Peter Turner
I use a similar one to this one, but its named hr and is a line of dashes rather than asterisks.
skamradt
I can't think of where I'd put such a comment that would actually be useful. I.e. in the sense of explaining what the code does.
Craig Young
That's the first part of a useful comment, (i.e. //********** //* This function does something awesome //*************) My company requires at a minimum //************** between procedures, which can get tedious when you're a guy who likes to use properties with get/set methods.
Peter Turner
+6  A: 

Very handy output debug string plus formatting


Name:
ods
Description:
Output Debug String with Format Code:

OutputDebugString(PAnsiChar(format('|',[])));


also, if I want to leave it in the code:

Name:
dods
Description:
Output Debug String with ifdef debug
Code:

{$IFDEF DEBUG}   
   OutputDebugString(PAnsiChar(format('|',[])));   
{$ENDIF}
Peter Turner
We have a little procedure ODS(const s: string) instead. :)
Ulrich Gerhardt
wow i have all most the same shortcut, but with out the format, I think im going to add that now :) thanks
Christopher Chase
Little reminder from the unicode conversion front - change to OutputDebugStringW or OutputDebugStringA accordingly
Peter Turner
Use PChar instead of PAnsiChar. That way, it'll work fine both in Unicode and non-Unicode versions of Delphi.
Martijn
+8  A: 

There are a handful of useful ones here, including a few based on CodeRush. These are the live templates, so they work in Delphi 2006 and up.

http://delphi.wikia.com/wiki/Delphi_Live_Templates

Bruce McGee
+3  A: 

If you do a lot of work on datasets these are handy.

Name: fbn

Description: DataSet FieldByName

|DataSet|.FieldByName( '|Field|' )|end|

Name: pbn

Description: DataSet ParamByName

|DataSet|.ParamByName( 'P_|Param|' )|end|
Ryan VanIderstine
+2  A: 

I did a couple that saved me lots of time. A few of those took the monotone out of property declarations. Then I did some to create type-safe enumerators, object lists and bucket lists. I probably should do one for collections too, but haven't yet.

These are all available on my blog.

Cobus Kruger