[fpc-pascal] polymorphism question

Darius Blaszijk dhkblaszyk at zeelandnet.nl
Thu Mar 2 22:57:25 CET 2006


I would like to declare a polymorph class. The class has several properties and it's the read and write specifiers that I want to be virtual abstract. So derived classes override the read and write specifiers. The problem however is that I get an EAbstractError. The property is still considered to be abstract according to the compiler. So what did I wrong? I have added an example below.
Is it perhaps not allowed to use this construct? What would then be the best way?
Darius

<<example>>

unit MyTest;

{$mode objfpc}{$H+}

interface

uses
  Classes, ComCtrls, SysUtils;

type
  TCustomClass = class
  private
    //virtual mehods
    function GetMyProperty: string; virtual; abstract;
    procedure SetMyProperty(Value: string); virtual; abstract;
  published

    property MyProperty: string Read GetMyProperty Write SetMyProperty;
  end;

  TMyClass = class(TCustomClass)
  private
    FMyProperty: string;

    function GetMyProperty: string; overload;
    procedure SetMyProperty(Value: string); overload;
  published
    property MyProperty;
  end;

implementation

function TMyClass .GetMyProperty: string;
begin
  Result := FMyProperty;
end;

procedure TMyClass .SetMyProperty(Value: string);
begin
  if Value = FMyProperty then
    exit;
    
  FMyProperty := Value;
end;
end.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20060302/7252d75d/attachment.html>


More information about the fpc-pascal mailing list