asi
asked on
abstruct properties
hi , does published/property can be abstruct ?
10x
Asi
10x
Asi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sassas,
You don't understand what *abstract* means.
If the error is "abstract error", it is because the derived class (you probably don't have one) is not implementing the methods.
Here is the idea for your benefit.
//The base class
type
TBaseClass = class (TObject)
public //must be public in this example, var x (below) calls this method
function GetSize: Integer; virtual; abstract;
procedure SetSize(ASize: Integer); virtual; abstract;
end;
//Ok, not notice that there is no implementation of TBaseClass.GetSize.
//TBaseClass represents an idea, not implemented code
//This is just how I think of it
//Now for the derived class
type
TDerivedClass = class( TBaseClass)
private
FSize: Integer;
public //or it can be protected in this example
function GetSize: Integer; override;
end;
implementation
TDerivedClass.GetSize: Integer;
begin
Result := FSize;
end;
//TDerivedClass.GetSize overrides TBaseClass.GetSize.
//Digest that for a while, now consider how to use this.
var x: TBaseClass;
begin
x := TDerivedClass.Create;
ShowMessage(IntToStr(x.Get Size));
x.SetSize(50); //<< this line causes an abstract run time error because
//TDerived class does not implement SetSize.
//The compiler will compile, but a warning will //be generated.
end;
//Calling x.GetSize will call the GetSize in TDerivedClass, not TBaseClass even though x is of type TBaseClass.
//x is of type TBaseClass, but it can be created using TDerivedClass since TDerivedClass is derived from TBaseClass
Just another thing, you shouldn't wrap up the essence of someone elses comment and try to get points for it.
You don't understand what *abstract* means.
If the error is "abstract error", it is because the derived class (you probably don't have one) is not implementing the methods.
Here is the idea for your benefit.
//The base class
type
TBaseClass = class (TObject)
public //must be public in this example, var x (below) calls this method
function GetSize: Integer; virtual; abstract;
procedure SetSize(ASize: Integer); virtual; abstract;
end;
//Ok, not notice that there is no implementation of TBaseClass.GetSize.
//TBaseClass represents an idea, not implemented code
//This is just how I think of it
//Now for the derived class
type
TDerivedClass = class( TBaseClass)
private
FSize: Integer;
public //or it can be protected in this example
function GetSize: Integer; override;
end;
implementation
TDerivedClass.GetSize: Integer;
begin
Result := FSize;
end;
//TDerivedClass.GetSize overrides TBaseClass.GetSize.
//Digest that for a while, now consider how to use this.
var x: TBaseClass;
begin
x := TDerivedClass.Create;
ShowMessage(IntToStr(x.Get
x.SetSize(50); //<< this line causes an abstract run time error because
//TDerived class does not implement SetSize.
//The compiler will compile, but a warning will //be generated.
end;
//Calling x.GetSize will call the GetSize in TDerivedClass, not TBaseClass even though x is of type TBaseClass.
//x is of type TBaseClass, but it can be created using TDerivedClass since TDerivedClass is derived from TBaseClass
Just another thing, you shouldn't wrap up the essence of someone elses comment and try to get points for it.
Anything abstract has to also be virtual, and you can't have virtual properties.
Here is a workaround for:
property Size: Integer read FSize write FSize;
Change the property to methods:
function GetSize: Integer; virtual; abstract;
procedure SetSize(ASize: Integer); virtual; abstract;
The two methods would be implemented in a derived class, and the value would be stored in a variable in that derived class.
Cheers,
Phil.