title: How to override an inherited class property in Delphi?
body: <p>In one file, I have a baseclass with a ID-property:</p>
  
  <pre><code>type
    TBase = class
    private  
      class function GetID(ACombo: TCombo): Integer; virtual;
      class procedure SetID(ACombo: TCombo; AValue: Integer); virtual;
    public  
      class property ID[ACombo: TCombo]: Integer read GetID write SetID;  
    end;
  </code></pre>
  
  <p>In a second file, I have another class, descending from TBase. By accident, or ignorance or what ever, a new property/field with the same name as an exsisting property/field was made.</p>
  
  <pre><code>type
    TSubBase = class(TBase)
    private  
      class function GetID(ACombo: TCombo): Integer; override;
      class procedure SetID(ACombo: TCombo; AValue: Integer); override;
    end;
  </code></pre>
  
  <p>And use these classes in next way:</p>
  
  <pre><code>  TBaseClass = class of TBase;
  
    function Base(): TBaseClass;
  
  implementation
  
  var
    BaseInstance: TBaseClass;
  
  function Base(): TBaseClass;
  begin
    if not Assigned(BaseInstance) then
    begin
       if SOME_PARAM then
        BaseInstance:= TBase
      else
        BaseInstance:= TSubBase;
    end;
    Result := BaseInstance;
  end;
  </code></pre>
  
  <hr>
  
  <pre><code>if Base.StationCode[cmbStation] = SOME_VALUE then
  </code></pre>
  
  <p>But I got the error while compiling:</p>
  
  <pre><code>[DCC Error] uMyFile.pas(69): E2355 Class property accessor must be a class field or class static method
  </code></pre>
  
  <hr>
  
  <hr>
  
  <p>I have been trying also with static keywords ... and based on advices from collegues below was found some workaround.</p>
  
  <pre><code>type
    TBase = class
    private  
      class function GetIDStatic(ACombo: TCombo): Integer; static;
      class procedure SetIDStatic(ACombo: TCombo; AValue: Integer); static;    
      class function GetID(ACombo: TCombo): Integer; virtual; abstract;
      class procedure SetID(ACombo: TCombo; AValue: Integer); virtual; abstract;
    public  
      class property ID[ACombo: TCombo]: Integer read GetIDStatic write SetIDStatic;  
    end;
  
    TSubBase = class(TBase)
    private  
      class function GetID(ACombo: TCombo): Integer; override;
      class procedure SetID(ACombo: TCombo; AValue: Integer); override;
    end;
  
    TBaseClass = class of TBase;
  
    function Base(): TBaseClass;
  
  implementation
  
  var
    BaseInstance: TBaseClass;
  
  function Base(): TBaseClass;
  begin
    if not Assigned(BaseInstance) then
    begin
       if SOME_PARAM then
        BaseInstance:= TBase
      else
        BaseInstance:= TSubBase;
    end;
    Result := BaseInstance;
  end;
  
  class function TBase.GetIDStatic(ACombo: TCombo): Integer; static;
  begin
    Result := BaseInstance.GetID(ACombo);
    // Or maybe below ?
    // Result := Base().GetID(ACombo); 
  end;
  
  class procedure TBase.SetIDStatic(ACombo: TCombo; AValue: Integer); static;
  begin
    BaseInstance.SetID(ACombo, AValue);
    // Or maybe below ?
    // Base().SetID(ACombo, AValue); 
  end;
  </code></pre>
  
  <p>But in this last variant - implementation is ugly and I agree with David about leave "the dreams" about an approach with using class properties AND SIMPLY refactor as described below:</p>
  
  <pre><code>  class properties ID[ACombo: TCombo]: Integer ....
    =&gt;&gt; 
    class function GetID(ACombo: TCombo): Integer; virtual;
    class pocedure SetID(ACombo: TCombo; AValue: Integer); virtual; 
  </code></pre>
  
  <p><strong>Thanks everyone for fun digging there!</strong></p>