Useful Delphi code templates

本秂侑毒 提交于 2019-12-03 13:18:58

问题


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.


回答1:


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




回答2:


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}



回答3:


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.




回答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|



回答5:


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.



来源:https://stackoverflow.com/questions/885024/useful-delphi-code-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!