How to create an auto-property faster in Delphi IDE?

走远了吗. 提交于 2019-12-01 03:11:31
Stefan Glienke

Since Delphi 2006 you can use LiveTemplates.

In Delphi XE for example:

  • type propf and hit Ctrl + J keystroke
  • write the property name and hit TAB key
  • write the property type name, hit TAB or ENTER key and you are done

You can find more information on how to write your own Live Templates here:

I use macros for that purpose.

For example I have model with fields

private
  FTitle: string;
  FName: string
  FAge: Integer

then I copy-paste the fields into published section and create macro

  1. Goto first field and hit Home
  2. Hit Ctrl + Shift + R to start recording macro
  3. Use Crtl + ->, Crtl + <- and End keys for navigation and convert first field to property like property Title: string Read FTitle Write FTitle;
  4. After that hit Home and go to next row
  5. Finish macro by hitting Ctrl + Shift + R
  6. For all other fields, just press Crtl + Shift + P

At first it seems difficult, but the skills will pay off.

In XE7 type prom and hit enter. It seems faster.

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