Solved

abstruct properties

Posted on 1998-11-19
3
138 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now