Solved

abstruct properties

Posted on 1998-11-19
3
141 Views
Last Modified: 2010-04-04
hi , does published/property can be abstruct ?

10x
Asi
0
Comment
Question by:asi
  • 2
3 Comments
 
LVL 3

Expert Comment

by:philipleighs
ID: 1347323
Only methods can be abstract.

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.

0
 
LVL 1

Accepted Solution

by:
sassas081597 earned 20 total points
ID: 1347324
The compiler lets you to create a property as shown in previous comment, however you cannot use it in your programm - error arizes. For not having errors try to declare this property as protected.
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1347325
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.GetSize));
   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.

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question