7

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Peter Turner
  • 11,199
  • 10
  • 68
  • 109

5 Answers5

11

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
  • 15,076
  • 6
  • 55
  • 70
8

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
  • 11,199
  • 10
  • 68
  • 109
5

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
  • 11,199
  • 10
  • 68
  • 109
  • I use a similar one to this one, but its named hr and is a line of dashes rather than asterisks. – skamradt May 19 '09 at 22:21
  • 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. – Disillusioned Dec 17 '09 at 12:20
  • 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 May 18 '10 at 13:44
4

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|
3

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
  • 8,338
  • 3
  • 61
  • 106