Kovpaev Alexey
Kovpaev Alexey

Reputation: 1786

Static property in Delphi

I'm having a problem with static property Calendar.

type
  TDateTime = class(TObject)
  private
  class var fcalendar: TCalendar;
  class procedure SetCalendar(const Value: TCalendar);
  public
  class property Calendar: TCalendar read fcalendar write SetCalendar;
 end;

implementation

  class procedure TDateTime.SetCalendar(const Value: TCalendar);
  begin
    if Value <> nil then
    begin
      TDateTime.fcalendar := Value;
    end;
  end;

The error occurred at 7th line

E2355 Class property accessor must be a class field or class static method

Upvotes: 3

Views: 5452

Answers (1)

Mason Wheeler
Mason Wheeler

Reputation: 84540

The problem is with the setter, and the error message explains exactly how you need to fix it: mark it as static. This does mean that you can't use a virtual class method as an accessor, but you're not doing that anyway, so it shouldn't be a problem.

class procedure SetCalendar(const Value: TCalendar); static;

Upvotes: 6

Related Questions