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?

3 Answers 3

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.

3
  • +1.. I'd give an extra bonus point for the ZX81 avatar if I could. :-) May 21, 2011 at 10:48
  • 8
    You can also write only Property Foo: TBar; and hit CTRL-SHIFT-C, that will create setter and field.
    – Harriv
    May 21, 2011 at 11:22
  • @Harriv - I'll add that to the answer May 21, 2011 at 11:31
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.

6

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.