Using Class Completion

From RAD Studio
Jump to: navigation, search

Go Up to How To Edit Code in the Code Editor


Class completion automates the definition of new classes by generating skeleton code for Delphi class members that you declare. The shortcut key for class completion is Ctrl+Shift+C.

Class completion works for procedures as well as classes. To add a new procedure to your class, you can do either of the following:

  • Define the procedure directly in the class, and autocomplete the implementation.
  • Define the implementation, and autocomplete the definition.

To use class completion

  1. In the Code Editor, declare a class in the interface section of a unit. For example, you might enter the following:
type TMyButton = class(TButton)
    property Size: Integer;
    procedure DoSomething;
end;
  1. Right-click the class declaration and choose Complete Class at Cursor.
Tip: You can also invoke Class Completion by placing the cursor within the class declaration and pressing Ctrl+Shift+C.

Class Completion automatically adds the read and write specifiers to the declarations for any properties that require them, and then adds skeleton code in the implementation section for each class method.

Tip: You can also use class completion to fill in interface declarations for methods that you define in the implementation section.

After invoking class completion, the previous sample code appears as follows:

type TMyButton = class(TButton)
  private
    FSize: Integer;
      procedure SetSize(const Value: Integer);
  published
      property Size: Integer read FSize write set_Size;
      procedure DoSomething;
end;

The following skeleton code is added to the implementation section:

{ TMyButton }

procedure TMyButton.DoSomething;
begin

end;

procedure TMyButton.SetSize(const Value: Integer);
begin
  FSize := Value;
end;

If your declarations and implementations are sorted alphabetically, class completion maintains their sorted order. Otherwise, new routines are placed at the end of the implementation section of the unit, and new declarations are placed in private sections at the beginning of the class declaration.

Tip: The Finish Incomplete Properties option on the Tools > Options > User Interface > Editor > Language > Code Insight Options determines whether class completion completes property declarations.

See Also