12

Is there any built in or external tool (wizard) to easily add class member (published field) with getters / setters?

adding each field requires me to write quite lot of code. Let's assume I need to add Foo: Bar; property.

I'll need to write

FFoo: TBar;
procedure SetFoo(const AValue: TBar);
function GetFoo: TBar;

...

property Foo: TBar read GetFoo write SetFoo

any tool to make it quick and easy?

migajek
  • 8,524
  • 15
  • 77
  • 116

3 Answers3

26

Type:

property Foo: TBar read GetFoo write SetFoo;

or:

property Foo: TBar read FFoo write SetFoo;

Then press CTRL-SHIFT-C

EDIT: The latter (setter and field combo) can be done even faster by writing only the following, followed by CTRL-SHIFT-C:

property Foo: TBar;

This shortcut also works if you write a method in your class and you wish to create the matching implementation.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
Steve Mayne
  • 22,285
  • 4
  • 49
  • 49
6

Just write the property declarataion:

property Foo: TBar read GetFoo write SetFoo;

then with your cursor on the property (or anywhere within the class declaration), press Ctrl-Shft-C and the IDE will autocomplete the declarations for you, including the implementation stubbs.

Please note that you may have to make sure that the "Finish incomplete properties" option is checked. You can find that under Tools | Options | Environment Options | Explorer.

Marjan Venema
  • 19,136
  • 6
  • 65
  • 79
6

You should have a look at ModelMaker Code Explorer. It will make your coding significantly faster.

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130